using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (q, y) = (c[0], c[1]); var s = ReadLine().Split(); var min = Calc(s, 0); var max = Calc(s, y); if (min > y || max < y) { WriteLine(-1); return; } var ng = -1L; var ok = y; while (ok - ng > 1) { var mid = (ok + ng) / 2; if (Calc(s, mid) >= y) ok = mid; else ng = mid; } if (Calc(s, ok) == y) WriteLine(ok); else WriteLine(-1); } static long Calc(string[] s, long x) { var stack = new Stack(); foreach (var si in s) { if (si == "+") { stack.Push(stack.Pop() + stack.Pop()); } else if (si == "min") { stack.Push(Math.Min(stack.Pop(), stack.Pop())); } else if (si == "max") { stack.Push(Math.Max(stack.Pop(), stack.Pop())); } else if (si == "X") { stack.Push(x); } else { stack.Push(long.Parse(si)); } } return stack.Pop(); } }