#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

string s;
bool f;
string func = "(),RL";
typedef pair<string, bool> psb;

string max_(string a, string b)
{

	if (a.size() > b.size()) return a;
	else if (a.size() < b.size()) return b;
	else return max(a, b);
}

pair<string, bool> solve(int l, int r)
{
	string tmp = s.substr(l, r - l);
	bool ff = true;
	REP(i, func.size())
	{
		if (tmp.find(func[i]) != string::npos) ff = false;
	}
	if (ff)
	{
		string res;
		if (tmp[0] == '0'&& tmp.size() > 1) return psb(res, false);
		FOR(i, l, r)
		{
			if (s[i] == '?') res.push_back('9');
			else res.push_back(s[i]);
		}
		return psb(res, true);
	}
	if  (r-l >= 6 &&
		(s[l] != 'R' || s[l] != 'L' || s[l] != '?') &&
		(s[l+1] == '(' || s[l+1] == '?') &&
		(s[r-1] == ')' || s[r-1] == '?'))
	{
		string res;
		FOR(i, l + 3, r - 2)
		{
			if (s[i] != ','&&s[i] != '?') continue;
			psb lhs = solve(l + 2, i);
			psb rhs = solve(i + 1, r - 1);
			if (lhs.second&&rhs.second)
			{
				string L = lhs.first, R = rhs.first;
				if (s[l] == 'R') res = max_(res, R);
				if (s[l] == 'L') res = max_(res, L);
				if (s[l] == '?')
				{
					res = max_(res, max_(R, L));
				}
			}
		}
		if (res == "") return psb(res, false);
		else return psb(res, true);
	}
	else return psb("", false);
}

int main()
{
	cin >> s;
	f = true;
	psb ans = solve(0, s.size());
	if (!ans.second) puts("invalid");
	else cout << ans.first << endl;
	return 0;
}