def f(i, j)
    return nil if S[i] =~ /[(),]/

    if S[i] == ?0
        if i == j
            return 0
        else
            return nil
        end
    end

    if S[i] =~ /\d/
        if S[i..j] =~ /[LR,()]/
            return nil
        else
            return S[i..j].tr(??, ?9).to_i
        end
    end

    if S[i] == ?L
        return nil if j - i < 5
        return nil if S[i+1] !~ /[(?]/
        return nil if S[j] !~ /[)?]/
        return l(i+2, j-1)
    end

    if S[i] == ?R
        return nil if j - i < 5
        return nil if S[i+1] !~ /[(?]/
        return nil if S[j] !~ /[)?]/
        return r(i+2, j-1)
    end

    if S[i..j] !~ /[LR,()]/
        return S[i..j].tr(??, ?9).to_i
    end

    return nil if j - i < 5
    return nil if S[i+1] !~ /[(?]/
    return nil if S[j] !~ /[)?]/

    x(i+2, j-1)
end

def l(i, j)
    return nil if j - i <= 1
    max = - Float::INFINITY
    (j-1).downto(i+1) do |k|
        break if 10 ** (k - i) <= max
        next if S[k] !~ /[?,]/
        next if ! f(k+1, j)
        if t = f(i, k-1)
            max = t if t > max
        end
    end
    max >= 0 ? max : nil
end

def r(i, j)
    return nil if j - i <= 1
    max = - Float::INFINITY
    (i+1..j-1).each do |k|
        break if 10 ** (j - k) <= max
        next if S[k] !~ /[?,]/
        next if ! f(i, k-1)
        if t = f(k+1, j)
            max = t if t > max
        end
    end
    max >= 0 ? max : nil
end

def x(i, j)
    return nil if j - i <= 1
    max = - Float::INFINITY
    (i+1..j-1).each do |k|
        next if S[k] !~ /[?,]/
        if (a = f(i, k-1)) && (b = f(k+1, j))
            max = [max, a, b].max
        end
    end
    max >= 0 ? max : nil
end

module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end
end
include Memoizable

memoize :f
memoize :l
memoize :r
memoize :x

S = gets.chomp
puts f(0, S.size-1) || 'invalid'