#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 ll 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--------------------*/

//typedef int Weight;
//struct Edge
//{
//	int from, to; Weight cost;
//	bool operator < (const Edge& e) const { return cost < e.cost; }
//	bool operator > (const Edge& e) const { return cost > e.cost; }
//};
//typedef vector<Edge> Edges;
//typedef vector<Edges> Graph;
//typedef vector<Weight> Array;
//typedef vector<Array> Matrix;
//void add_edge(Graph &g, int from, int to, Weight cost)
//{
//	g[from].push_back(Edge{ from, to, cost });
//}
//
//void dijkstra(Graph &g, int s, Array &d)
//{
//	d.assign(g.size(), INF);
//	d[s] = 0;
//	typedef pair<Weight, int> P;
//	priority_queue<P, vector<P>, greater<P>> que;
//	que.push(P(0, s));
//	while (!que.empty())
//	{
//		Weight dist = que.top().first;
//		int v = que.top().second;
//		que.pop();
//		if (d[v] < dist) continue;
//		REP(i, g[v].size())
//		{
//			Edge e = g[v][i];
//			if (d[e.to] > d[v] + e.cost)
//			{
//				d[e.to] = d[v] + e.cost;
//				que.push(P(d[e.to], e.to));
//			}
//		}
//	}
//}

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

string s;

pair<string, bool> solve(int l, int r)
{
	if (l == r) return make_pair("", false);
	//cout << l << " " << r << endl;
	bool f = true;
	FOR(i, l, r)
	{
		if (s[i] != '?' && !isdigit(s[i])) f = false;
	}
	if (f)
	{
		if (r - l > 1 && s[l] == '0') return make_pair("", false);
		string t;
		FOR(i, l, r)
		{
			if (isdigit(s[i])) t += s[i];
			else t += '9';
		}
		return make_pair(t, true);
	}
	if (r - l < 6) return make_pair("", false);
	if (s[l] != 'R' && s[l] != 'L' && s[l] != '?') return make_pair("", false);
	if (s[l + 1] != '(' && s[l + 1] != '?') return make_pair("", false);
	if (s[r - 1] != ')' && s[r - 1] != '?') return make_pair("", false);
	string ans;
	FOR(i, l + 3, r - 2)
	{
		if (s[i] != ',' && s[i] != '?') continue;
		auto lhs = solve(l + 2, i);
		if (lhs.first.size() > 1 && lhs.first[0] == '0') lhs.second = false;
		auto rhs = solve(i + 1, r - 1);
		if (rhs.first.size() > 1 && rhs.first[0] == '0') rhs.second = false;
		if (!(lhs.second && rhs.second)) continue;;
		if (s[l] == 'L') ans = s_max(ans, lhs.first);
		else if (s[l] == 'R') ans = s_max(ans, rhs.first);
		else ans = s_max(ans, s_max(lhs.first, rhs.first));
		//cout << i << " " << ans << endl;
	}
	if (ans == "") return make_pair("", false);
	else
	{
		//cout << l << " " << r <<" "<< ans << endl;
		return make_pair(ans, true);
	}
}

int main()
{
	cin >> s;
	//cout << solve(6, 17).first << endl;
	
	auto ans = solve(0, s.size());
	if (ans.second) cout << ans.first << endl;
	else puts("invalid");
	return 0;
}

Measured memory_bytes: 3200