#include <stdio.h>
#include <stdlib.h>

void push(int);
int pop(void);

int stack[100];
static int top = 0;

int main(){
  int x, y, b, c, i=0, j;
  char a[100];
  int fcount=0, ecount=0;

  while( scanf("%s", a) != EOF ){
    if(a[0] >= '0' && a[0] <= '9'){
      b = atoi(a);
      push(b);
      fcount++;
    }

    if(a[0] == '+' || a[0] == '-' || a[0] == '*'){
      x = pop();
      y = pop();
      if(a[0] == '+') c = y+x;
      else if(a[0] == '-') c = y-x;
      else c = y*x;

      if(c < -1000000000 || c > 1000000000) exit(3);

      push(c);
      ecount++;
    }
  }

  if(fcount < 2 || fcount > 100 || ecount < 1 || ecount > 99) exit(5);

  printf("%d\n", pop());
  return 0;
}

void push(int a){
  int i;

  if(top > 100) exit(1);
  stack[top] = a;
  top++;

}

int pop(void){
  int x;

  if(top < 0) exit(2);
  top--;
  x = stack[top];

  return x;
}

