Example

Input

R?????,2?)


Output

29
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
string s;
int n;
string dp[60][60];
string F(string a,string b){
	if(a.size()>b.size())return a;
	if(a.size()<b.size())return b;
	if(a>b)return a;
	return b;
}
string f(int l,int r){
	if(!(dp[l][r]==""||dp[l][r]=="*"))return dp[l][r];
	string out="/";
	{
		bool h=true;
		string t="";
		loop(j,l,r)if(isdigit(s[j]))t+=s[j];
		else if(s[j]=='?')t+="9";
		else{
			h=false;
			break;
		}
		if(r-l>1&&s[l]=='0')h=false;
		if(h)out=t;
	}
	if(r-l>=6){
		if(!(s[l]=='L'||s[l]=='R'||s[l]=='?'))return out;
		if(!(s[l+1]=='('||s[l+1]=='?'||s[l+1]=='?'))return out;
		if(!(s[r-1]==')'||s[r-1]=='?'||s[r-1]=='?'))return out;
		loop(j,l+3,r-2)if(s[j]==','||s[j]=='?'){
			string a=f(l+2,j),b=f(j+1,r-1);
			if(a=="/"||b=="/")continue;
			if(s[l]=='L'||s[l]=='?')out=F(out,a);
			if(s[l]=='R'||s[l]=='?')out=F(out,b);
		}
	}
	return dp[l][r]=out;
}
signed main(){
	rep(i,60)rep(j,60)dp[i][j]="";
	
	cin>>s;
	n=s.size();
	string out=f(0,n);
	if(out!="/")cout<<out<<endl;
	else cout<<"invalid"<<endl;
}







