package shangtangkeji;
//逆波兰表达式,后缀表达式
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
//错误用例:2 1 + 3 *
//错误用例:2 1 + 0 /
public class Main1 {
public static int evalRPN(String[] tokens) {
Stack<Integer> stack = new Stack<>();
for (String s : tokens) {
if (s.equals("+")) {
stack.push(stack.pop() + stack.pop());
} else if (s.equals("-")) {
stack.push(-stack.pop() + stack.pop());
} else if (s.equals("*")) {
stack.push(stack.pop() * stack.pop());
} else if (s.equals("/")) {
//不允许除数为0的情况
int num1 = stack.pop();
if(num1 == 0) {
System.out.println(0/0);
return Integer.MIN_VALUE;
}
stack.push(stack.pop() / num1);
} else {
stack.push(Integer.parseInt(s));
}
}
return stack.pop();
}
public static void main(String[] args) throws IOException{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String str = input.readLine();
String[] tokens = str.split(" ");
System.out.println(evalRPN(tokens));
}
}