Problem: Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of n the program was run. Help Petya, carry out the inverse function!

Mostly, the program consists of a function in C++ with the following simplified syntax:

  * function ::= int f(int n) {operatorSequence}
  * operatorSequence ::= operator | operator operatorSequence
  * operator ::= return arithmExpr; | if (logicalExpr) return arithmExpr;
  * logicalExpr ::= arithmExpr > arithmExpr | arithmExpr < arithmExpr | arithmExpr == arithmExpr
  * arithmExpr ::= sum
  * sum ::= product | sum + product | sum - product
  * product ::= multiplier | product * multiplier | product / multiplier
  * multiplier ::= n | number | f(arithmExpr)
  * number ::= 0|1|2|... |32767



The whitespaces in a operatorSequence are optional.

Thus, we have a function, in which body there are two kinds of operators. There is the operator "return arithmExpr;" that returns the value of the expression as the value of the function, and there is the conditional operator "if (logicalExpr) return arithmExpr;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the n parameter are used in the function. All the constants are integers in the interval [0..32767].

The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations ">" (more), "<" (less) and "==" (equals) also have standard meanings.

Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division "/" is a usual integer division where the remainder is omitted.

Examples of arithmetical operations: 

<image>

Guaranteed that for all values of n from 0 to 32767 the given function is performed correctly. That means that:

1. Division by 0 never occures.

2. When performing a function for the value n = N recursive calls of the function f may occur only for the parameter value of 0, 1, ..., N - 1. Consequently, the program never has an infinite recursion.

3. As the result of the sequence of the operators, the function always returns a value.

We have to mention that due to all the limitations the value returned by the function f is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of n parameter. That's why the f function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of n from the interval [0..32767] and a value of f(n) from the same interval.

Given the value of f(n), and you should find n. If the suitable n value is not unique, you should find the maximal one (from the interval [0..32767]).

Input

The first line has an integer f(n) from the interval [0..32767]. The next lines have the description of the function f. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes.

Output

Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes).

Examples

Input

17
int f(int n)
{
if (n &lt; 100) return 17;
if (n &gt; 99) return 27;
}


Output

99


Input

13
int f(int n)
{
if (n == 0) return 0;
return f(n - 1) + 1;
}


Output

13

Input

144
int f(int n)
{
if (n == 0) return 0;
if (n == 1) return n;
return f(n - 1) + f(n - 2);
}

Output

24588

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Point {
  T x, y;
  Point() {}
  Point(T xx, T yy) : x(xx), y(yy) {}
};
template <typename T>
bool operator<(const Point<T> &p1, const Point<T> &p2) {
  return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
template <typename T>
Point<T> operator-(const Point<T> &p1, const Point<T> &p2) {
  return Point<T>(p1.x - p2.x, p1.y - p2.y);
}
template <typename T>
T operator^(const Point<T> &p1, const Point<T> &p2) {
  return p1.x * p2.y - p2.x * p1.y;
}
const int MAXN = 32768;
const char LESS = '<', MORE = '>', EQUAL = '=';
const char TN = 'N', TF = 'f', TI = 'I', TE = 'E', TS = 'S';
const int PLUS = 10000001;
const int MINUS = 10000002;
const int MUL = 10000003;
const int DIV = 10000004;
vector<int> values;
void execute(int n);
struct Aryfm {
  char Type;
  int num;
  vector<Aryfm> v;
  Aryfm() {}
  Aryfm(string s, char type = TE) {
    string ts;
    Type = type;
    for (int(i) = 0; (i) < s.size(); i++) {
      Aryfm a;
      if (s[i] == 'f') {
        ts = "";
        int lvl = 0;
        for (i += 2; i < s.size(); i++) {
          if (s[i] == '(') lvl++;
          if (s[i] == ')') lvl--;
          if (lvl < 0) break;
          ts += s[i];
        }
        a = Aryfm(ts, TF);
      } else if (s[i] == 'n') {
        a.Type = TN;
      } else if (isdigit(s[i])) {
        ts = "";
        for (; i < s.size() && isdigit(s[i]); i++) ts += s[i];
        i--;
        a.Type = TI;
        a.num = atol(ts.c_str());
      } else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') {
        a.Type = TS;
        if (s[i] == '+') a.num = PLUS;
        if (s[i] == '-') a.num = MINUS;
        if (s[i] == '*') a.num = MUL;
        if (s[i] == '/') a.num = DIV;
      } else
        while (true)
          ;
      v.push_back(a);
    }
  }
  int Calc(int n) {
    if (Type == TN)
      return n;
    else if (Type == TI || Type == TS)
      return num;
    vector<int> c;
    for (int(i) = 0; (i) < v.size(); i++) {
      c.push_back(v[i].Calc(n));
    }
    for (int(i) = 0; (i) < c.size(); i++) {
      if (c[i] == MUL) {
        c[i - 1] = (c[i - 1] * c[i + 1]) % MAXN;
        c.erase(c.begin() + i);
        c.erase(c.begin() + i);
        i--;
      } else if (c[i] == DIV) {
        c[i - 1] = (c[i - 1] / c[i + 1]);
        c.erase(c.begin() + i);
        c.erase(c.begin() + i);
        i--;
      }
    }
    for (int(i) = 0; (i) < c.size(); i++) {
      if (c[i] == PLUS) {
        c[i - 1] = (c[i - 1] + c[i + 1]) % MAXN;
        c.erase(c.begin() + i);
        c.erase(c.begin() + i);
        i--;
      } else if (c[i] == MINUS) {
        c[i - 1] = (c[i - 1] - c[i + 1]);
        while (c[i - 1] < 0) c[i - 1] += MAXN;
        c.erase(c.begin() + i);
        c.erase(c.begin() + i);
        i--;
      }
    }
    if (c.size() != 1)
      while (true)
        ;
    int res = c[0];
    if (Type == TF) {
      res = values[res];
    }
    return res;
  }
};
struct Cond {
  char cond;
  Aryfm l, r, ret;
};
vector<Cond> f;
void execute(int n) {
  if (values[n] != -1) return;
  for (int(i) = 0; (i) < f.size(); i++) {
    int l = f[i].l.Calc(n);
    int r = f[i].r.Calc(n);
    if (f[i].cond == MORE && l > r || f[i].cond == LESS && l < r ||
        f[i].cond == EQUAL && l == r) {
      values[n] = f[i].ret.Calc(n);
      return;
    }
  }
}
string ts, s;
void Parse() {
  ts = s;
  s = "";
  for (int(i) = 0; (i) < ts.size(); i++) {
    if (ts[i] == '{') {
      for (++i; i < ts.size(); i++) {
        if (ts[i] == '}') break;
        if (!isspace(ts[i])) s += ts[i];
      }
      break;
    }
  }
  for (int(i) = 0; (i) < s.size(); i++) {
    Cond c;
    if (s[i] == 'r') {
      c.cond = EQUAL;
      c.l = Aryfm("1");
      c.r = Aryfm("1");
    } else if (s[i] == 'i') {
      for (; i < s.size() && s[i] != '('; i++)
        ;
      i++;
      ts = "";
      for (; i < s.size() && s[i] != '=' && s[i] != '<' && s[i] != '>'; i++)
        ts += s[i];
      c.l = Aryfm(ts);
      if (s[i] == '=') c.cond = EQUAL;
      if (s[i] == '<') c.cond = LESS;
      if (s[i] == '>') c.cond = MORE;
      if (s[i] == '=') i++;
      i++;
      ts = "";
      for (; i + 1 < s.size() && s[i + 1] != 'r'; i++) ts += s[i];
      c.r = Aryfm(ts);
      i++;
    }
    if (s[i] == 'r') {
      for (; i < s.size() && s[i] != 'n'; i++)
        ;
      i++;
      ts = "";
      for (; i < s.size() && s[i] != ';'; i++) ts += s[i];
      c.ret = Aryfm(ts);
      f.push_back(c);
    }
  }
}
int main() {
  values.assign(MAXN, -1);
  int fn;
  cin >> fn;
  ts = "";
  while (getline(cin, ts)) {
    s += " " + ts;
  }
  Parse();
  for (int(i) = 0; (i) < MAXN; i++) {
    execute(i);
  }
  for (int i = values.size() - 1; i >= 0; i--) {
    if (values[i] == fn) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}