Example

Input

R?????,2?)


Output

29
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

string s;
vector<vector<string>> dp;

bool comp(const string &a,const string &b){
    if(a=="-1"){return true;}
    if(b=="-1"){return false;}
    if(a=="-2"){return true;}
    if(b=="-2"){return false;}
    if(a.size()!=b.size()){return a.size()<b.size();}
    return a<b;
}

//[l,r)
string & dfs(ll l,ll r){
    if(dp[l][r]!="-1"){return dp[l][r];}
    if(l>=r){return dp[l][r]="-2";}
    if(r-l==1 && s[l]=='0'){return dp[l][r]="0";}
    if(s[l]=='0'){return dp[l][r]="-2";}
    string ret;
    bool j=true;
    for(ll i=l;i<r && j;i++){
        if('0'<=s[i] && s[i]<='9'){
            ret.push_back(s[i]);
        }
        else if(s[i]=='?'){ret.push_back('9');}
        else{j=false;}
    }
    if(j){return dp[l][r]=ret;}
    if(r-l<6){return dp[l][r]="-2";}
    if(s[l+1]!='(' && s[l+1]!='?'){return dp[l][r]="-2";}
    if(s[r-1]!=')' && s[r-1]!='?'){return dp[l][r]="-2";}
    if(s[l]=='L'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(i+1,r-1)=="-2"){continue;}
            if(comp(dp[l][r],dfs(l+2,i))){dp[l][r]=dp[l+2][i];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    else if(s[l]=='R'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(l+2,i)=="-2"){continue;}
            if(comp(dp[l][r],dfs(i+1,r-1))){dp[l][r]=dp[i+1][r-1];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    else if(s[l]=='?'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(l+2,i)=="-2" || dfs(i+1,r-1)=="-2"){continue;}
            if(comp(dp[l][r],dp[i+1][r-1])){dp[l][r]=dp[i+1][r-1];}
            if(comp(dp[l][r],dp[l+2][i])){dp[l][r]=dp[l+2][i];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    return dp[l][r]="-2";
}


int main(){
    cin>>s;
    dp.resize(s.size(),vector<string>(s.size()+1,"-1"));
    dfs(0,s.size());
    if(dp[0][s.size()]=="-2"){cout<<"invalid"<<endl;}
    else{cout<<dp[0][s.size()]<<endl;}
    
    
    return 0;
}

