#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 100
int stack[MAX];
int top = -1;
void push(int val) {
    if (top <MAX -1) {
        stack[++top]= val;
    }
}
int pop(){
    if (top >=0) {
        return stack[top--];
    }
    return -9999;
    }
    int evalute(char *exp) {
        int len = srlen(exp);
        for (int i = len-1;i>=0;i--) {
            char c = exp[i];
            if (isspace(c)) continue;
            if (isdigit(c)) {
                push(c - '0');
            }
            else if (c == '+'||c == '-'||c == '*'|| c == /) {
                if (top < 1) return -9999;
                int a = pop();
                int b = pop();
                int result;
                switch (c) {
                    case '+':result = a+b; break;
                    case '-':result = a-b; break;
                    case '*':result = a*b; break;
                    case '/';
                    if (b==0) return -9999;
                    result =a/b;
                    break;
                    default:return -9999;
                }
                push(result);
            }
            else {
                return -9999;
            }
                }
            if (top !=0) return -9999;
            return pop();
        }
    int main(){
        char expr[MAX];
        if (!fgets(expr,sizeof(expr),stdin)) {
            printf("Invalid input\n");
            return 0;
        }
        int result = evaluate(expr);
        if (result == -9999) {
            printf("Invalid input\n");
        } else {
            printf("%d\n".result);
        }
        return 0;
    }