Example

Input

R?????,2?)


Output

29
#include<bits/stdc++.h>
using namespace std;
 
 
struct strint{
  string x;
  strint() {
    x = "";
  }
  int size()const{
    return x.size();
  }
  char operator[](int id) const {
    return x[id];
  }
  bool operator<(const strint &ot) const{
    if( size() < ot.size() ) return true;
    if( size() > ot.size() ) return false;
    for(int i=0;i<size();i++){
      if( x[i] < ot[i] ) return true;
      if( x[i] > ot[i] ) return false;
    }
    return false;
  }
  void operator+=(const string &s) {
    x+=s;
  }
  strint operator=(const string &s){
    x = s;
    return *this;
  }
  strint operator=(char s[]){
    x = s;
    return *this;
  }
};
 
 
char buf[111];
strint memo[55][55];
strint memn[55][55];
strint memr[55][55];
strint meml[55][55];
strint parse(int l,int r);
 
strint number(int l,int r){
  //cout << "number : "<< l <<" , " << r << endl;
  strint &ret = memn[l][r];
  if( ret.x != "" ) return ret;
  strint res;
  if( buf[l] == '0' ){
    if( l+1 == r ) return memn[l][r] = (string)"0";
    else return memn[l][r] = (string)"/";
  }
  while( l < r && (isdigit(buf[l]) || buf[l] == '?') ){
    if( buf[l] == '?' ) res += (string)"9";
    else res.x += buf[l];    
    l++;
  }
  ret = res;
  //cout << res << " " << l << "-"<< r << endl;
  if( l == r ) return ret;
  return ret = (string)"/";
}
 
strint parseR(int l,int r){
  strint &ret = memr[l][r];
  if( ret.x != "" ) return ret;
  ret = (string)"/";
  //cout << "R : "<< l <<" , " << r << endl;
  if( (buf[l] == 'R' || buf[l] == '?') && (buf[r-1] == ')' || buf[r-1] == '?' ) ){
    l++; r--;
    if( buf[l] == '(' || buf[l] == '?' ) {
      l++;
      for(int i=l+1;i+1<r;i++){       
        if( (buf[i] == ',' || buf[i] == '?') && parse(l,i).x != "/" ){
          //strint x = parse(i+1,r);
          //if( x != "/" ) return x;
          ret = max( ret, parse(i+1,r) );
        }
      }
    }
  } 
  return ret;
}
 
strint parseL(int l,int r){
  strint &ret = meml[l][r];
  if( ret.x != "" ) return ret;
  ret = (string)"/";
  //cout << "L : "<< l <<" , " << r << endl;
  if( (buf[l] == 'L' || buf[l] == '?') && (buf[r-1] == ')' || buf[r-1] == '?' ) ){
    l++; r--;
    if( buf[l] == '(' || buf[l] == '?' ) {
      l++;
      for(int i=l+1;i+1<r;i++){       
        if( (buf[i] == ',' || buf[i] == '?') && parse(i+1,r).x != "/" ){
          //ret = parse(l,i);
          //if( ret != "/" ) return ret;
          ret = max( ret, parse(l,i) );
        }
      }
    }
  } 
  return ret;
}
 
 
strint parse(int l,int r){
  //cout << l << ", " << r << endl;
  strint &ret = memo[l][r];
  if( ret.x != "" ) return ret;
  if( l >= r ) return ret = (string)"/";
  return ret = max( number(l,r), max( parseR(l,r) , parseL(l,r) ) );
}
 
int main(){
  cin >> buf;
  strint res = parse(0,strlen(buf));
  if( res.x == "/" ) cout << "invalid" << endl;
  else cout << res.x << endl;
 
}