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

typedef struct node{
  struct node *next;
  int value;
}Node;

Node *head = NULL;

int pop(){
  if( head == NULL)
    exit( 1 );
  Node *tmp = head;
  int value = tmp -> value;
  head = head -> next;
  free( tmp );
  return value;
}

void push( int value ){
  Node *node = ( Node * )malloc( sizeof( Node ) );
  node -> next = head;
  node -> value = value;
  head = node;
}

int main( void ){
  int ch, n = 0, state = 0;
  while( ( ch = getchar() ) != '\n' && ch != EOF ){
    if( ch == ' ' ){
      if( state == 1 ){
        push( n );
      }
      state = 0;
    }
    else if( ch == '*' ){
      push( pop() * pop() );
      state = 0;
    }
    else if( ch == '+' ){
      push( pop() + pop() );
      state = 0;
    }
    else if( ch == '-' ){
      int i = pop(), j = pop();
      push( j - i );
      state = 0;
    }
    else if( '0' <= ch && ch <= '9' ){
      int i = ch & 0xF;
      if( state == 1 )n = n * 10 + i;
      else n = i;
      state = 1;
    }
    else exit(1);
  }
  printf("%d\n", pop() );
  return 0;
}

