Example

Input

R?????,2?)


Output

29
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

string str;

bool cmp(string s, string t){
	if(s.size() > t.size()) return true;
	if(s.size() < t.size()) return false;
	rep(i,s.size()){
		if(s[i] > t[i]) return true;
		if(s[i] < t[i]) return false;
	}
	return true;
}

string func(string s){
	if(s == "0") return s;
	bool ok = true;
	string ret;
	rep(i,s.size()){
		if(s[i]=='R'||s[i]=='L'||s[i]=='('||s[i]==')'||s[i]==','){
			ok = false;
			break;
		}
		if(i == 0 && s[i] == '0'){
			return ret;
		}
	}
	if(ok){
		rep(i,s.size()){
			if(s[i] == '?') s[i] = '9';
		}
		return s;
	}
	if(s.size() < 6) return ret;
	
	if(s[0] != 'R' && s[0] != 'L' && s[0] != '?') return ret;
	if((s[1] != '(' && s[1] != '?') || (s[s.size()-1] != ')' && s[s.size()-1] != '?')) return ret;
	for(int i = 3; i <= s.size()-3; i++){
		if(s[i] != ',' && s[i] != '?') continue;
		string l = s.substr(2,i-2);
		string r = s.substr(i+1,s.size()-2-i);
		r = func(r);
		l = func(l);
		if(r.size() == 0 || l.size() == 0) continue;
		if(s[0] == 'R'){
			if(cmp(r,ret)) ret = r;
		}
		if(s[0] == 'L'){
			if(cmp(l,ret)) ret = l;
		}
		if(s[0] == '?'){
			if(cmp(l,r)) r = l;
			if(cmp(r,ret)) ret = r;
		}
	}
	return ret;
}

int main(){
	cin >> str;
	string out = func(str);
	if(out.size() == 0) puts("invalid");
	else cout << out << endl;
}