Example

Input

R?????,2?)


Output

29
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

string grid[100][100];

void solve() {
    string s;
    cin >> s;
    REP(i, s.length()) {
        string now;
        for (int q = i; q < s.length(); ++q) {
            if (s[q] == '?') {
                now.push_back('9');
            }
            else if ((s[q] >= '0' && s[q] <= '9')) {
                now.push_back(s[q]);
            }
            else break;
            grid[i][q] = now;
            if (now == "0") break;
        }
    }
    for (int len = 6; len <= s.length(); ++len) {
        REP(q, (int)s.length() - len + 1) {
            if (!(s[q + 1] == '(' || s[q + 1] == '?')) continue;
            if (!(s[q + len - 1] == ')' || s[q + len - 1] == '?')) continue;

            if (s[q] == '?' || s[q] == 'L') {
                //left
                for (int j = 3; j < len - 2; ++j) {
                    if (s[q + j] == ',' || s[q + j] == '?') {
                        //ok
                        string b = grid[q + 2][q + j - 1];
                        if (b.empty() == true) continue;
                        if (grid[q + j + 1][q + len - 2].empty() == true) continue;
                        if (b.length() > grid[q][q + len - 1].length()) {
                            grid[q][q + len - 1] = b;
                        }
                        if (b.length() == grid[q][q + len - 1].length()&&b > grid[q][q+len-1]) {
                            grid[q][q + len - 1] = b;
                        }
                    }
                }
            }
            
            if (s[q] == '?' || s[q] == 'R') {
                //right
                for (int j = 3; j < len - 2; ++j) {
                    if (s[q + j] == ',' || s[q + j] == '?') {
                        //ok
                        string b = grid[q + j + 1][q + len - 2];
                        if (b.empty() == true) continue;
                        if (grid[q + 2][q + j - 1].empty() == true) continue;
                        if (b.length() > grid[q][q + len - 1].length()) {
                            grid[q][q + len - 1] = b;
                        }
                        if (b.length() == grid[q][q + len - 1].length() && b > grid[q][q + len - 1]) {
                            grid[q][q + len - 1] = b;
                        }
                    }
                }
            }

        }

    }
    if (grid[0][s.length() - 1].empty() == true) {
        cout << "invalid" << endl;
        return;
    }
    cout << grid[0][s.length()-1] << endl;
}

#undef int
int main() {
    init();
    solve();
}
