# -*- coding: utf-8 -*- s = raw_input() ops, nums = [], [] n = len(s) ret = -1 flag = True i = 0 while i < n: if s[i].isdigit(): j = i num = 0 while j < n and s[j].isdigit(): num = num * 10 + ord(s[j]) - ord('0') j += 1 nums.append(num) i = j - 1 elif s[i] == ')': if len(ops) == 0: flag = False break op = ops[-1] ops.pop() if op == '^' and len(nums) > 0: ans = nums[-1] nums.pop() nums.append(ans + 1) elif (op == '*' or op == '+') and len(nums) > 1: a, b = nums[-1], nums[-2] nums.pop() nums.pop() nums.append((a * b) if op == '*' else (a + b)) else: flag = False break if len(ops) == 0 or ops[-1] is not '(': flag = False break ops.pop() if len(ops) == 0: ret = nums[-1] if len(ops) == 0 and i < n - 1 and len(nums) > 0: nums.pop() elif s[i] == ' ': pass else: ops.append(s[i]) i += 1 if len(ops) > 0: flag = False if ret is not -1: print ret else: print -1 if flag == False else nums[-1]