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

typedef struct {
    int *stk;
    int ptr;
    int size;
} Stk;

bool isDlmChar(char c, char dlm) {
    return c == dlm || c == '\0';
}

int split(char** des, int desNum, char* src, char dlm) {
    int cnt = 0;
    int src_len = strlen(src);

    for(int i = 0; i < src_len && cnt < desNum; i++) {
        des[cnt++] = &src[i];
        while(!isDlmChar(src[i], dlm)) {
            i++;
        }
        src[i] = '\0';
    }

    return cnt;
}

bool isStringOnlyNumber(char* str) {
    return strlen(str) == strspn(str, "0123456789");
}

bool initStk(Stk *s, int size) {
    if((s->stk = malloc(size * sizeof(int))) == NULL) {
        return false;
    }

    s->ptr = 0;
    s->size = size;
    return true;
}

bool isStkEmpty(Stk *s) {
    return s->ptr <= 0;
}

bool isStkFull(Stk *s) {
    return s->ptr >= s->size;
}

bool pushStk(Stk *s, int x) {
    if(isStkFull(s)) {
        return false;
    }

    s->stk[s->ptr++] = x;
    return true;
}

bool popStk(Stk *s, int *x) {
    if(isStkEmpty(s)) {
        return false;
    }

    *x = s->stk[--s->ptr];
    return true;
}

void teminateStk(Stk *s) {
    free(s->stk);

    s->ptr = s->size = 0;
}

int main(void) {
    Stk s;
    int stkSize = 256;
    char buf[1024];

    if(!initStk(&s, stkSize)) {
        return 1;
    }

    fgets(buf, sizeof(buf), stdin);
    buf[strlen(buf) - 1] = '\0';

    char *ptr[256];
    int num = split(ptr, sizeof(ptr) / sizeof(ptr[0]), buf, ' ');

    int x;
    for(int i = 0; i < num; i++) {
        if(isStringOnlyNumber(ptr[i])) {
            pushStk(&s, atoi(ptr[i]));
        } else {
            int a, b;
            if(!popStk(&s, &a) || !popStk(&s, &b)) {
                return 1;
            }
            if(!strcmp(ptr[i], "+")) {
                x = a + b;
            } else if(!strcmp(ptr[i], "-")) {
                x = b - a;
            } else if(!strcmp(ptr[i], "*")) {
                x = a * b;
            }

            if(!pushStk(&s, x)) {
                return 1;
            }
        }
    }

    if(!popStk(&s, &x)) {
        return 1;
    }
    printf("%d\n", x);

    teminateStk(&s);
    return 0;
}
