#include <iostream>
#include <vector>
#include <string>

using namespace std;

string smax(string A, string B) {
    if (A.length() < B.length()) {
        return B;
    } else if (A.length() > B.length()) {
        return A;
    } else {
        return (A > B ? A : B);
    }
}

string S;

string expr(int l, int r);

// fill [l, r) with digits
string number(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    for (int i = l; i <= r; ++i) {
        if (S[i] != '?' && !isdigit(S[i])) return ret = "";
        ret.push_back(S[i] == '?' ? '9' : S[i]);
    }
    if (ret[0] == '0' && ret.length() > 1) return ret = "";
    return ret;
}

string left(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    if (r <= l + 1 ||
        !(S[l] == 'L' || S[l] == '?') ||
        !(S[l + 1] == '(' || S[l + 1] == '?') ||
        !(S[r] == ')' || S[r] == '?')) return ret;
    l += 2;
    r -= 1;

    for (int i = l + 1; i <= r - 1; ++i) {
        if (S[i] != ',' && S[i] != '?') continue;
        string L = expr(l, i - 1);
        string R = expr(i + 1, r);
        if (L.empty() || R.empty()) continue;
        ret = smax(ret, L);
    }
    return ret;
}

string right(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = "";
    if (r <= l + 1 ||
        !(S[l] == 'R' || S[l] == '?') ||
        !(S[l + 1] == '(' || S[l + 1] == '?') ||
        !(S[r] == ')' || S[r] == '?')) return ret;
    l += 2;
    r -= 1;

    for (int i = l + 1; i <= r - 1; ++i) {
        if (S[i] != ',' && S[i] != '?') continue;
        string L = expr(l, i - 1);
        string R = expr(i + 1, r);
        if (L.empty() || R.empty()) continue;
        ret = smax(ret, R);
    }
    return ret;
}

string expr(int l, int r) {
    static vector<vector<string>> dp(S.length(), vector<string>(S.length(), "hoge"));
    string& ret = dp[l][r];
    if (ret != "hoge") return ret;

    ret = number(l, r);
    ret = smax(ret, left(l, r));
    ret = smax(ret, right(l, r));
    return ret;
}

int main() {
    cin >> S;
    string ans = expr(0, S.length() - 1);
    cout << (ans.empty() ? "invalid" : ans) << endl;
    return 0;
}

