Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 55;

bool check(const string &s) {
  return s.empty() || s == "0" || s[0] != '0';
}

class BigNum {
private:
  string s;
public:
  BigNum() {
    s = "";
  }
  BigNum(const string &s) {
    if (!check(s)) this->s = "";
    else this->s = s;
  }
  bool operator < (const BigNum &x) const {
    if (s.size() != x.s.size()) return s.size() < x.s.size();
    return s < x.s;
  }
  bool operator > (const BigNum &x) const {
    return x < *this;
  }
  bool operator != (const BigNum &x) const {
    return s != x.s;
  }
  bool operator == (const BigNum &x) const {
    return s == x.s;
  }
  bool operator <= (const BigNum &x) const {
    return *this == x || *this < x;
  }
  bool operator >= (const BigNum &x) const {
    return *this == x || x < *this;
  }
  string getString() const {
    return s;
  }
};

int N;
string S;
bool vis[MAXN][MAXN];
BigNum mem[MAXN][MAXN];

BigNum rec(int l, int r) {
  BigNum &res = mem[l][r];
  if (vis[l][r]) {
    return res;
  }
  res = BigNum();
  vis[l][r] = true;
  if ((S[l] == '?' || S[l] == 'L' || S[l] == 'R') &&
      (S[l+1] == '?' || S[l+1] == '(') &&
      (S[r-1] == '?' || S[r-1] == ')')) {
    for (int i = l+3; i < r-2; ++i) {
      if (S[i] != '?' && S[i] != ',') continue;
      BigNum a = rec(l+2, i);
      BigNum b = rec(i+1, r-1);
      if (a != BigNum() && b != BigNum()) {
        if (S[l] == '?' || S[l] == 'L') {
          res = max(res, a);
        }
        if (S[l] == '?' || S[l] == 'R') {
          res = max(res, b);
        }
      }
    }
  }
  {
    string x = "";
    for (int i = l; i < r; ++i) {
      if (S[i] == '?') {
        x += "9";
      } else if (isdigit(S[i])) {
        x += S[i];
      } else {
        x = "";
        break;
      }
    }
    res = max(res, BigNum(x));
  }
  return res;
}

int main() {
  while (cin >> S) {
    N = S.size();
    S += "$";
    memset(vis, 0, sizeof(vis));
    string ans = rec(0, N).getString();
    if (ans == "") ans = "invalid";
    cout << ans << endl;
  }
  return 0;
}