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

void Stack(void);
void push(int);
int pop(void);
int isempty(void);
int data(char);

typedef struct StackNode *StackPointer;
struct StackNode{
  int key;
  StackPointer next;
};

StackPointer head, tail, t;

int main(){

  int value1, value2;
  char c;

  Stack();
  while(1){
      c=getchar();
      if(c=='\n'){
	  printf("%d\n",pop());
	  break;
	}
      else if('0' <= c && c <= '9'){
	  push(data(c));

	}
      else{
	  value1=pop();
	  value2=pop();

	  if(c=='+') push(value1+value2);
	  else if(c=='-') push(value1-value2);
	  else if(c=='*') push(value1*value2);
	}
    }
  return 0;
}

void push(int x){
  t = malloc(sizeof *t);
  t->key = x;
  t->next = head->next;
  head->next = t;
}

int pop(){
  if(isempty()==0)
    {
      int x;
      t = head->next;
      head->next = t->next;
      x = t->key;
      free(t);
      return x;
    }
  else{
      printf("Stack is empty!!\n");
      exit(1);
    }
}

int isempty(){
  return head->next == tail;
}

int data(char c){
  char str[2];
  str[0]=c;
  str[1]='\0';
  return atoi(str);
}

void Stack(void){
  head = malloc(sizeof(*head));
  tail = malloc(sizeof(*tail));
  head->next = tail;
  tail->next = tail;
}

