Example

Input

R?????,2?)


Output

29
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

bool eq(const string &s, size_t pos, char c2) {
  return pos < s.length() and (s[pos] == c2 or s[pos] == '?');
}

bool is_greater(const string &s1, const string &s2) {
  if (s1 == "invalid") {
    return true;
  } else if (s2 == "invalid") {
    return false;
  }
  return s1.length() == s2.length()? s1 < s2: s1.length() < s2.length();
}

string compute(string s) {
  if ((isdigit(s[0]) and (s.length() == 1 or s[0] != '0')) or s[0] == '?') {
    for (size_t i = 0; i < s.length(); ++i) {
      if (not (isdigit(s[i]) or s[i] == '?')) {
        break;
      }
      if (i == s.length() - 1) {
        for (size_t j = 0; j < s.length(); ++j) {
          if (s[j] == '?') {
            s[j] = '9';
          }
        }
        return s;
      }
    }
  }
  if ((eq(s, 0, 'R') or eq(s, 0, 'L')) and eq(s, 1, '(') and eq(s, s.length() - 1, ')')) {
    vector<string> sv, cands;
    for (size_t i = 3; i < s.length() - 2; ++i) {
      if (eq(s, i, ',')) {
        string sl = compute(s.substr(2, i - 2));
        string sr = compute(s.substr(i + 1, s.length() - i - 2));
        if (sl != "invalid" and sr != "invalid") {
          if (eq(s, 0, 'L')) {
            cands.push_back(sl);
          }
          if (eq(s, 0, 'R')) {
          cands.push_back(sr);
          }
        }
      }
    }
    if (not cands.empty()) {
      return *max_element(cands.begin(), cands.end(), is_greater);
    }
  }
  return "invalid";
}

int main() {
  string s;
  cin >> s;
  cout << compute(s) << endl;
  return 0;
}