def main(): _ = int(input()) arr = list(input().split()) st = [] for a in arr: if a == "+": x = st.pop() y = st.pop() st.append(x + y) elif a == "-": x = st.pop() y = st.pop() st.append(y - x) else: st.append(int(a)) print(st[0]) if __name__ == "__main__": main()