#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 9;
stack<int> k;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int t = 0;
string s; getline(cin, s);
for (int i = s.size() - 1; i >= 0; i--) {\
char c = s[i];
if (c >= '0' && c <= '9') t = t * 10 + (c - '0');
if (c == ' ') {
k.push(t);
t = 0;
} else {
int a = k.top(); k.pop(); int b = k.top(); k.pop();
if (c == '+') k.push(a + b);
else if (c == '-') k.push(fabs(a - b));
else if (c == '*') k.push(a * b);
else k.push(a / b);
}
}
cout << k.top() << endl;
return 0;
}```