--stack　逆ポーランド電卓

import Data.Char

data TOKEN = NUM Int | ADD | PRD | SUB deriving (Eq,Show)

tokenize::String->TOKEN
tokenize "+" = ADD
tokenize "-" = SUB
tokenize "*" = PRD
tokenize str = NUM (read str)
--stack input return
--スタックは数値のみのリスト
calc::[TOKEN] -> [TOKEN] ->Int
calc (NUM i:NUM j:st) (ADD:ls) = calc (NUM (i+j):st) ls
calc (NUM i:NUM j:st) (SUB:ls) = calc (NUM (j-i):st) ls
calc (NUM i:NUM j:st) (PRD:ls) = calc (NUM (i*j):st) ls
calc st (NUM i:ls) = calc (NUM i:st) ls
calc [NUM i] [] = i --return answer

fun::String->Int
fun = (calc []).(map tokenize).words

main::IO()
main=do
  str<-getLine
  print (fun str)
