Example

Input

R?????,2?)


Output

29
/*
 * 2680.cc: LR
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

string dp0[MAX_N][MAX_N], dp1[MAX_N][MAX_N], dp2[MAX_N][MAX_N];

/* subroutines */

bool lt_num(string &s0, string &s1) {
  int l0 = s0.size(), l1 = s1.size();
  if (l0 != l1) return l0 < l1;
  for (int i = 0; i < l0; i++)
    if (s0[i] != s1[i]) return (s0[i] < s1[i]);
  return false;
}

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n; i++) {
    if (s[i] >= '0' && s[i] <= '9') dp0[i][i] = string(1, s[i]);
    else if (s[i] == '?') dp0[i][i] = string(1, '9');
    dp1[i][i] = dp0[i][i];
  }

  for (int l = 2; l <= n; l++)
    for (int i = 0, j = l - 1; j < n; i++, j++) {
      if (((s[i] >= '0' && s[i] <= '9') || s[i] == '?') &&
	  dp0[i + 1][j].size() > 0) {
	char ch = (s[i] == '?') ? '9' : s[i];
	string sd = string(1, ch) + dp0[i + 1][j];
	if (lt_num(dp0[i][j], sd)) dp0[i][j] = sd;
	if (sd[0] != '0' && lt_num(dp1[i][j], sd)) dp1[i][j] = sd;
      }	
      if (((s[j] >= '0' && s[j] <= '9') || s[j] == '?') &&
	  dp0[i][j - 1].size() > 0) {
	char ch = (s[j] == '?') ? '9' : s[j];
	string sd = dp0[i][j - 1] + ch;
	if (lt_num(dp0[i][j], sd)) dp0[i][j] = sd;
	if (sd[0] != '0' && lt_num(dp1[i][j], sd)) dp1[i][j] = sd;
      }

      if (l >= 6 &&
	  (s[i + 1] == '(' || s[i + 1] == '?') &&
	  (s[j] == ')' || s[j] == '?')) {
	bool lok = (s[i] == 'L' || s[i] == '?');
	bool rok = (s[i] == 'R' || s[i] == '?');
	if (lok || rok)
	  for (int k = i + 3; k < j - 1; k++)
	    if (s[k] == ',' || s[k] == '?') {
	      string &dp00 = dp1[i + 2][k - 1], &dp01 = dp2[i + 2][k - 1];
	      string &dp10 = dp1[k + 1][j - 1], &dp11 = dp2[k + 1][j - 1];
	      string &dp0 = lt_num(dp00, dp01) ? dp01 : dp00;
	      string &dp1 = lt_num(dp10, dp11) ? dp11 : dp10;
	      if (dp0.size() > 0 && dp1.size() > 0) {
		if (lok && lt_num(dp2[i][j], dp0)) dp2[i][j] = dp0;
		if (rok && lt_num(dp2[i][j], dp1)) dp2[i][j] = dp1;
	      }
	    }
      }
    }

  string &d1 = dp1[0][n - 1], &d2 = dp2[0][n - 1];
  string &maxdp = lt_num(d1, d2) ? d2 : d1;
  if (maxdp.size() == 0) puts("invalid");
  else cout << maxdp << endl;
  return 0;
}