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

#define NUMBER '0'
#define MAXVAL 100

struct Node{
    int data;
    struct Node * next;
};

typedef struct Node Node;

Node * create_node(int new_data){
    Node * new_node = (Node *) malloc(sizeof(Node));
    if(!new_node){
        fprintf(stderr, "could not allocate a node.\n");
        exit(1);
    }
    new_node->data = new_data;
    new_node->next = NULL;
    return new_node;
}

void push_front(Node ** head, int new_data){
    Node * new_node = create_node(new_data);
    new_node->next = *head;
    *head = new_node;
}

int pop_front(Node ** phead){
    Node * del_node = *phead;
    int ret = (*phead)->data;
    *phead = (*phead)->next;
    free(del_node);
    return ret;
}

void push_back(Node ** phead, int new_data){
    Node * new_node = create_node(new_data);
    Node * pos_node = *phead;
    if(*phead == NULL){
        new_node->next = *phead;
        *phead = new_node; 
    }
    else{
        while(pos_node->next){
            pos_node = pos_node -> next;
        }
        pos_node->next = new_node;
    }
}

void clear_list(Node * head){
    while(head){
        Node * target = head;
        head = head->next;
        free(target);
    }
}

void print_list(const Node * head){
    while(head){
        printf("| %d |-> ", head->data);
        head = head->next;
    }
    printf("NULL\n");
}

void print_stack(const Node * head){
    while(head){
        printf("| %d | ",head->data);
        head=head->next;
    }
    printf("bottom\n");
}

/*
int getop_old(char s[]){
    int i, c;
    while(1){
        c = getchar();
        if(c != ' ') break;
    }
    s[0] = c;
    s[1] ='\0';

    if(!isdigit(c)){
        return c;
    }
    i = 1;
    while(1){
        c = getchar();
        if(!isdigit(c)) break;
        s[i] = c;
        i++;
    }
    i++;
    s[i]='\0';
    return NUMBER;
}*/

void test(size_t size){
    Node * bottom = NULL;

    int data;
    
    for(size_t i = 0; i < size; i++){
        scanf("%d",&data);
        push_front(&bottom, data);
    }
    print_stack(bottom);
    //print_list(bottom);
    for(size_t i = 0; i < size; i++){
        int data = pop_front(&bottom);
        printf("pop(): %d\n", data);
    }
    clear_list(bottom); //ここまでtest
    return;
}


int main(){
    /*size_t size;
    scanf("%zu", &size);
    test(size);*/


    Node * top = NULL;
    int type;
    char s[MAXVAL];
    while(1){
        int type = scanf("%s",s);
        if(type == EOF) break;
        if(s[0] == '+'){
            int data1 = pop_front(&top);
            int data2 = pop_front(&top);
            push_front(&top, data1 + data2);
        }
        else if(s[0] == '-'){
            int data1 = pop_front(&top);
            int data2 = pop_front(&top);
            push_front(&top, data2 - data1);
        }
        else if(s[0] == '*'){
            int data1 = pop_front(&top);
            int data2 = pop_front(&top);
            push_front(&top, data1 * data2);            
        }
        else{
            int data1 = atoi(s);
            push_front(&top, data1);
        }
    }
    printf("%d\n",pop_front(&top));
    clear_list(top);


    return 0;

}


Measured memory_bytes: 2104