// id: ALDS1_3_A
// CPU: 00:00sec  Memory: KB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>

#define MAX_SIZE 100
#define LEN 6

typedef int Item;
struct stack_type {
	Item *contents;
	int top;
	int size;
};
typedef struct stack_type *Stack;

Stack create(int size);
void destroy(Stack s);
void make_empty(Stack s);
bool is_full(Stack s);
bool is_empty(Stack s);
void push(Stack s, Item i);
Item top(Stack s);
Item pop(Stack s);
static void terminate(const char *message);

int main(void)
{
	Stack operands = create(MAX_SIZE);
	char str[LEN + 1];
	//FILE *fp = fopen("d:\\data\\oj\\aojALDS1_3_A.txt", "r");

	while ( fscanf(stdin, "%s", str) != EOF )
		if ( isdigit(str[0]) )
			push(operands, atoi(str));
		else {
			char operator = str[0];
			int lhs, rhs, res;

			rhs = pop(operands);
			lhs = pop(operands);

			switch ( operator ) {
				case '+':
					res = lhs + rhs;
					break;
				case '-':
					res = lhs - rhs;
					break;
				case '*':
					res = lhs * rhs;
					break;
			}

			push(operands, res);
		}

	printf("%d\n", pop(operands));

	//fclose(fp);
	destroy(operands);

	return 0;
}

Stack create(int size)
{
	Stack s = malloc(sizeof(struct stack_type));
	if ( s == NULL )
		terminate("Error in create: stack could not be created.");

	s->contents = malloc(sizeof(Item) * size);
	if ( s->contents == NULL ) {
		destroy(s);
		terminate("Error in create: fail to allocate space for contents.");
	}
	s->top = 0;
	s->size = size;

	return s;
}

void destroy(Stack s)
{
	free(s->contents);

	free(s);
}

void make_empty(Stack s)
{
	s->top = 0;
}

bool is_full(Stack s)
{
	return s->top == s->size;
}

bool is_empty(Stack s)
{
	return s->top == 0;
}

void push(Stack s, Item i)
{
	if ( is_full(s) ) {
		destroy(s);
		terminate("Error in push: stack is full.");
	}

	s->contents[s->top++] = i;
}

Item top(Stack s)
{
	if ( is_empty(s) ) {
		destroy(s);
		terminate("Error in top: stack is empty.");
	}

	return s->contents[s->top - 1];
}

Item pop(Stack s)
{
	if ( is_empty(s) ) {
		destroy(s);
		terminate("Error in pop: stack is empty.");
	}

	return s->contents[--s->top];
}

static void terminate(const char *message)
{
	printf("%s\n", message);
	exit(EXIT_FAILURE);
}
