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

long stack[100];
int stack_p = 0;

void push(long value)
{
    stack[stack_p++] = value;
}

long pop()
{
    int value = 0;
    if (stack_p > 0) {
        value = stack[stack_p - 1];
        stack_p--;
    }
    return value;
}

int main(int argc, char *argv[])
{
    char str[7] = {'\0'};
    long result = 0;

    while (scanf("%s", str) != EOF) {
        if (str[0] == '+') {
            long b = pop();
            long a = pop();
            push(a + b);
        }
        else if (str[0] == '-') {
            long b = pop();
            long a = pop();
            push(a - b);
        }
        else if (str[0] == '*') {
            long b = pop();
            long a = pop();
            push(a * b);
        }
        else if (str[0] == 'Z') {
            break;
        }

        else {
            push(atoi(str));
        }
    }
    printf ("%ld\n", pop());
    return 0;
}