let f st op =
  let x1 = Stack.pop st and
      x2 = Stack.pop st in
  Stack.push (op x2 x1) st;
  st;;

let () =
  let st:int Stack.t = Stack.create () and
      l = read_line () |> Str.split (Str.regexp_string " ")
  in
  let rec loop ops = function
      [] -> Stack.pop ops
    | h::t ->
       let result =
         match h with
           "+" -> f ops (+)
         | "-" -> f ops (-)
         | "*" -> f ops ( * )
         | h -> Stack.push (int_of_string h) ops;ops
       in
       loop result t
  in Printf.printf "%d\n" (loop st l)
;;