#include<stdio.h>
#include<ctype.h>
#include<string.h>
 
 int stack[100];
 int top=-1;
 void push(int x){
     stack[++top] = x;
 }
 int pop(){
     return (top>=0)? stack[top--] : -999999;
     }
     int evaluate(char *s){
         int n = strlen(s);
         top = -1;
         for(int i= n-1;i>=0;i--){
             char c=s[i];
             if(isdigit(c)) push(c - '0');
             else if(c=='+'||c=='-'||c=='/'){
                 if(top<1)return -999999;
                 int a=pop();
                 int b=pop(),r;
                 if(c=='+')r=a+b;
                 else if(c=='-')r=a-b;
                 else if(c=='*')r=a*b;
                 else{
                     if(b==0) 
                     return -999999;
                     r=a/b;
                 }
                 push(r);
             }else return -999999;
         }
         return (top==0) ? pop(): -999999;
     }
     int mainn(){
         char expr[101];
         scanf("%s",expr);
         int res = evaluate(expr);
         if(res==-999999) printf("Invalid input\n");
         else printf("%d\n",res);
         return 0;
     }