#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;

string S;
vector<char> DP[50][51];//[i][j]:=[i,j)????????§???

bool isnumber(int l, int r){
    if(r-l>=2&&S[l]=='0') return false;
    for(int i=l;i<r;i++){
        if(!(isdigit(S[i])||S[i]=='?')) return false;
    }
    return true;
}

vector<char> number(int l, int r){
    vector<char> ret(0);
    if(isnumber(l,r)){
        for(int i=l;i<r;i++){
            ret.push_back((S[i]=='?'?'9':S[i]));
        }
    }
    return ret;
}

vector<char> segment(int l, int r){
    auto comp = [](const vector<char>& A, const vector<char>& B){
        if(A.size()<B.size()) return true;
        else if(A.size()>B.size()) return false;
        else{
            for(int i=0;i<A.size();i++){
                if(A[i]>B[i]) return false;
                else if(A[i]<B[i]) return true;
            }
            return true;
        }
    };
    vector<char> ret=number(l,r);
    if(ret.size()) return ret;
    if(r-l>=6&&(S[l]=='R'||S[l]=='L'||S[l]=='?')&&(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]=='?'){
                if(DP[l+2][i].size()&&DP[i+1][r-1].size()){
                    if(S[l]=='R')ret=max(ret,DP[i+1][r-1],comp);
                    if(S[l]=='L')ret=max(ret,DP[l+2][i],comp);
                    if(S[l]=='?')ret=max({ret,DP[l+2][i],DP[i+1][r-1]},comp);
                }
            }
        }
    }
    return ret;
}

int main(){
    cin>>S;
    for(int len=1;len<=S.size();len++){
        for(int i=0;i+len<=S.size();i++){
            DP[i][i+len]=segment(i,i+len);
            // cout<<'['<<i<<") : "<< DP[i][i+len]<<endl;
        }
    }
    if(DP[0][S.size()].size()){
        // cout<<DP[0][S.size()]<<endl;
        for(auto c:DP[0][S.size()]) cout<<c;
        cout<<endl;
    }else{
        cout<<"invalid"<<endl;
    }
    return 0;
}