#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; inline bool is_digit(string s) { return all_of(s.begin(), s.end(), ::isdigit); } int main() { int n; cin >> n; vector s(n); rep(i, n) cin >> s[i]; vector q; rep(i, n) { if (is_digit(s[i])) q.push_back(stoi(s[i])); else { if (s[i] == "+") { int a = q.back(); q.pop_back(); int b = q.back(); q.pop_back(); q.push_back(a + b); } else if (s[i] == "-") { int a = q.back(); q.pop_back(); int b = q.back(); q.pop_back(); q.push_back(b - a); } else { assert(false); } } } assert(q.size() == 1); cout << q[0] << endl; return 0; }