type stack = ST of int * stack | NULL

let a_ = read_line () |> Str.split (Str.regexp " ") 
|> Array.of_list
let n = Array.length a_

let to_int st =
 match st with 
  ST (num1, ST (num2, s)) -> (num1, num2, s)
  |_ -> (0, 0, NULL)

let rec f a i st n =
 if i = n then 
  match st with
  ST (num, _) -> num
  |_ -> -1
 else if a.(i) = "+" then 
  let (num1, num2, s) = to_int st in
  f a (i+1) (ST (num1+num2, s)) n
 else if a.(i) = "-" then
  let (num1, num2, s) = to_int st in
  f a (i+1) (ST (num2-num1, s)) n
 else if a.(i) = "*" then
  let (num1, num2, s) = to_int st in
  f a (i+1) (ST (num1*num2, s)) n
 else let num = int_of_string a.(i) in
      f a (i+1) (ST (num, st)) n

let () =
 let n = Array.length a_ in
 f a_ 0 NULL n |> Printf.printf "%d\n" 