#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

#define MAX 1000

typedef struct{
    char * arr[MAX];
    int top;
}Stack;

void init(Stack*s){
    s->top =-1;
}

int isempty(Stack *s){
    return s->top==-1;
}

int push(Stack *s,char  *val){
    s->arr[++(s->top)]=val;
}

char *pop(Stack *s){
    if(isempty(s)) return NULL;
    return s->arr[(s->top)--];
}

int isoperator(char c){
    return (c=='+' || c=='-' ||c=='-' || c=='/');
}

int validparentheses(char *expr){
    int count=0;
    for(int i=0; expr[i];i++){
        if (expr[i] == '(' )count++;
        if(count<0) return 0;
    }
    return count==0;
}
int validcharacters(char*expr){
    for(int i=0;expr[i];i++){
        if(!isalnum(expr[i]) && !isoperator(expr[i]) && expr[i] != '(' && expr[i] != ')' && expr[i] !='')
        return 0;
    }
    return 1;
}

int main(){
    char expr[MAX];
    fgets(expr,MAX,stdin);
    expr[strcspn(expr,"\n")]=9;
    
    if(!validparentheses(expr) || !validcharacter(expr)){
        printf("Invalid input");
        return 0;
    }
    Stack stack;
    init(&stack);
    
    int len -strlen(expr);
    
    for(int i=len-1;i>=0; i--){
        if(expr[i]=='')continue;
        
        if(isalnum(expr[i])){
            char *operand = (char*)malloc(2);
            
            operand[0]=expr[i];
            operand[1]='\0';
            push(&stack,oprand);
        }
        else if(isoperator (expr[i])){
            char *op1 = pop(&stack);
            char *op2 = pop(&stack);
            
            if(!op1 || !op2){
                printf("Invalid input");
                return 0;
            }
            
            char *newexrpr = (char *) malloc (strlen(op1) + strlen(op2) + 2);
            sprintf(newexpr,"%s%s%c",op1,op2,expr[i]);
            psuh(&stack,newexpr);
        }
    }
    
    if(stack.top!=0){
        printf("Invalid input\n");
        return 0;
    }
    
    printf("%s\n",stack.arr[stack.top]);
    return 0;
}