#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"


string st;


bool operator<(const string& l, const string& r) {
	if (l.size() == r.size()) {
		for (int i = 0; i < l.size(); ++i) {
			if (l[i] != r[i])return l[i] < r[i];
			
		}
		return false;
	}
	else {
		return l.size() < r.size();
	}
}

string memo[51][51];
string getans(const int l, const int r) {
	if (memo[l][r] != "#")return memo[l][r];
	{
		string ans;
		bool ok = true;
		for (int c = l; c < r; ++c) {
			if (!isdigit(st[c])) {
				if (st[c] == '?') {
					ans.push_back('9');
				}
				else {
					ok = false;
				}
			}
			else {
				if (c == l&&st[c] == '0'&&r-l!=1)ok = false;
				ans.push_back(st[c]);
			}
		}
		if (ok)return memo[l][r]=ans;
	}
	if (r - l < 6)return "";
	else
	{
		bool canl, canr;
		if (st[l] == '?') {
			canl = true; canr = true;
		}
		else if (st[l] == 'L') {
			canl = true; canr = false;
		}
		else if (st[l] == 'R') {
			canl = false; canr = true;
		}
		else if (isdigit(st[l])) {
			canl = false; canr = false;
		}
		else if (st[l] == ',') {
			canl = false; canr = false;
		}
		else {
			canl = false; canr = false;
		}
		if ((st[l + 1] == '(' || st[l + 1] == '?') && (st[r - 1] == ')' || st[r - 1] == '?')) {

		}
		else {
			canl = false;
			canr = false;
		}
		string ans;
		for (int conma = l + 3; conma <= r - 3; ++conma) {
			if (st[conma] == '?' || st[conma] == ',') {

				string lst = getans(l + 2, conma);
				string rst = getans(conma + 1, r - 1);
				if (!lst.empty() && !rst.empty()) {
					if (canl) {
						if (ans < lst)ans = lst;
					}
					if (canr) {
						if (ans < rst)ans = rst;
					}
				}
			}
		}
		return memo[l][r]=ans;
	}
	
}

int main() {
	cin >> st;
	for (int i = 0; i <= 50; ++i) {
		for (int j = 0; j <= 50; ++j) {
			memo[i][j] = '#';
		}
	}
	string ans=getans(0, st.size());
	if (ans.empty())ans = "invalid";
	cout << ans << endl;
	return 0;
}