#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100

char stack[MAX][MAX];
int top=-1;

int isOperator(char c){
    return (ch == '+' || ch=='-' || ch=='*' || ch=='/');
}
void push(char str[]){
    strcpy(stack[++top], str);
}
char* pop(char str[]){
      strcpy(str, stack[top--]);
}

int main(){
    char prefix[MAX];
    scanf("%s", prefix);
    int len = strlen(prefix);
    
    for(int i=len-1;i>=0;i--){
        char c=prefix[i];
        
        if(isalnum(c)){
            char temp[2];
            temp[0] = c;
            temp[1] = '\0';
            push(temp);
        }
        else if(isOperator(c)){
            if(top < 1){
                printf("Invalid input");
                return 0;
            }
            char op1[MAX], op2[MAX], expr[MAX];
            
            pop(op1);
            pop(op2);
            
            strcpy(expr, op1);
            strcpy(expr, op2);
            
            int l = strlen(expr);
            expr[l] = c;
            expr[l + 1]='\0';
            
            push(expr);
        }
        else {
            printf("Invalid input");
            return 0;
        }
    }
    if(top != 0){
        printf("Invalid input");
        return 0;
    }
    printf("%s", stack[top]);
    return 0;
}
//             temp[0] = prefix[i];
//             temp[1] = '\0';
//             push(temp);
//         }
//         else if(isOperator(prefix[i])){
//             if(top<1){
//                 printf("Invalid input");
//                 return 0;
//             }
//             strcpy(op1, pop());
//             strcpy(op2, pop());
            
//             temp[0] = '\0';
//             strcpy(temp, op1);
//             strcpy(temp, op2);
//             int l = strlen(temp);
//             temp[l] = prefix[i];
//             temp[l + 1]='\0';
            
//             push(temp);
//         }
//         else{
//             printf("Invalid input");
//             return 0;
//         }
//     }
//     if(top != 0){
//         printf("Invalid input");
//         return 0;
//     }
//     printf("%s",pop());
//     return 0;
// }