type obj = Op of string | Num of int

let rev_split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  doit str []

let str_fold_left f init str =
  let n = String.length str - 1 in
  let rec doit i acc =
    if i > n then acc
    else doit (i + 1) (f acc str.[i])
  in
  doit 0 init

let num_p s =
  str_fold_left (fun acc c -> acc && (c >= '0' && c <= '9')) true s

let read lst =
  let rec doit acc = function
    | [] -> acc
    | n :: tl when num_p n -> doit (Num (int_of_string n) :: acc) tl
    | op :: tl -> doit (Op op :: acc) tl
  in
  doit [] lst

let calc lst =
  let rec doit acc = function
    | [] -> acc
    | Op op :: tl -> begin
        match acc with
        | Num x :: Num y :: z -> begin
            if op = "+" then doit (Num (y + x) :: z) tl
            else if op = "-" then doit (Num (y - x) :: z) tl
            else doit (Num (y * x) :: z) tl
          end
        | _ -> exit 1
      end
    | Num n :: tl -> doit (Num n :: acc) tl
  in
  match doit [] lst with
  | [Num n] -> n
  | _ -> exit 1

let _ =
  let lst = read (rev_split (read_line ()) ' ') in
  Printf.printf "%d\n" (calc lst)