#include "bits/stdc++.h"
using namespace std;

struct node {
	int l, r;
};

char s[100];
int len;
node ans[100][100];

node max(node n1, node n2) {
	if (n1.l < 0 && n1.r < 0) return n2;
	if (n2.l < 0 && n2.r < 0) return n1;
	if (n1.r - n1.l > n2.r - n2.l) return n1;
	if (n2.r - n2.l > n1.r - n1.l) return n2;
	int i, j;
	for (i = n1.l, j = n2.l; i <= n1.r && j <= n2.r; i++, j++) {
		if (s[i] != '?' && s[j] != '?') {
			if (s[i] < s[j]) return n2;
			if (s[i] > s[j]) return n1;
		} else if (s[i] == '?') {
			if (s[j] != '9' && s[j] != '?') return n1;
		} else if (s[j] == '?') {
			if (s[i] != '9' && s[i] != '?') return n2;
		}
	} 
	return n1;
}

node dfs(int l, int r) {
	if (ans[l][r].l != -2 && ans[l][r].r != -2) return ans[l][r];

	bool b = true;
	for (int i = l; i <= r && b; i++) if (s[i] == 'L' || s[i] == 'R' || s[i] == ',' || s[i] == '(' || s[i] == ')') b = false;
	if (b) {
		if (l != r && s[l] == '0') return ans[l][r] = {-1, -1};
		return ans[l][r] = {l, r};
	}
	
	if (s[l] != 'L' && s[l] != 'R' && s[l] != '?') return ans[l][r] = {-1, -1};
	if (s[l + 1] != '(' && s[l + 1] != '?') return ans[l][r] = {-1, -1};
	if (s[r] != ')' && s[r] != '?') return ans[l][r] = {-1, -1};
	node maxl = {-1, -1};
	node maxr = {-1, -1};
	for (int i = l + 3; i <= r - 2; i++) {
		if (s[i] == '?' || s[i] == ',') {
			node ll = dfs(l + 2, i - 1), rr = dfs(i + 1, r - 1);
			if (ll.l != -1 && ll.r != -1 && rr.l != -1 && rr.r != -1)
				maxl = max(maxl, ll), maxr = max(maxr, rr);
		}
	}
	if (s[l] == 'L') return ans[l][r] = maxl;
	else if (s[l] == 'R') return ans[l][r] = maxr;
	else if (s[l] == '?') return ans[l][r] = max(maxl, maxr);
	return ans[l][r] = {-1, -1};
}

int main() {
	scanf("%s", s);
	len = strlen(s);

	for (int i = 0; i < len; i++) for (int j = 0; j < len; j++) ans[i][j].l = ans[i][j].r = -2;

	dfs(0, len - 1);

	if (ans[0][len - 1].l == -1 && ans[0][len - 1].r == -1) printf("invalid");
	else 
		for (int i = ans[0][len - 1].l; i <= ans[0][len - 1].r; i++) 
			if (s[i] == '?') printf("9"); else printf("%c", s[i]);
	printf("\n");
	return 0;
}