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