Example

Input

R?????,2?)


Output

29
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
bool used[51][51];
string ans[51][51];
bool great(string x, string y) {
	int l1 = x.length(); int l2 = y.length();
	if (l1 != l2)return l1 < l2;
	return x < y;
}
string maax(string x, string y) {
	if (x == "invalid")return y;
	else if (y == "invalid")return x;
	if (great(x, y))return y; return x;
}
string number(string x) {
	int len = x.length();
	if (!len)return "invalid";
	if (x[0] == '0'&&len>1)return "invalid";
	string res;
	rep(j, len) {
		if ('0' <= x[j] && x[j] <= '9') {
			res.push_back(x[j]);
		}
		else if (x[j] == '?') {
			res.push_back('9');
		}
		else {
			res = "invalid"; break;
		}
	}
	return res;
}
int n;
string s;
string dfs(int le, int ri) {
	if (used[le][ri])return ans[le][ri];
	used[le][ri] = true;
	if (le > ri)return ans[le][ri] = "invalid";
	string res = number(s.substr(le, ri - le + 1));
	if (res != "invalid")return ans[le][ri]=res;
	res = "invalid";
	if (s[ri] != '?'&&s[ri] != ')')return ans[le][ri] = "invalid";
	if (le + 1 >= n || (s[le + 1] != '?'&&s[le + 1] != '('))return ans[le][ri] = "invalid";
	for (int i = le + 2; i <= ri - 1; i++) {
		if (s[i] == '?' || s[i] == ',') {
			string l = dfs(le + 2, i - 1); string r = dfs(i + 1, ri - 1);
			if (l == "invalid" || r == "invalid")continue;
			if (s[le] == 'L' || s[le] == '?')res = maax(res, l);
			if (s[le] == 'R' || s[le] == '?')res = maax(res, r);
		}
	}
	return ans[le][ri]=res;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s; n = s.length();
	cout << dfs(0, n - 1) << endl;
	/*rep(i, n) {
		Rep(j, i, n) {
			cout << i << " " << j << endl;
			cout << ans[i][j] << endl;
		}
	}*/
	return 0;
}
