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

    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(s, 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(s, 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] !~ /[)?]/

    max = l(s, i+2, j-1)

    if max
        t = r(s, i+2, j-1)
        max = t if t && t > max
    else
        max = l(s, i+2, j-1)
    end

    max
end

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

def r(s, i, j)
    return nil if j - i <= 1
    max = - Float::INFINITY
    (i+1..j-1).each do |k|
        next if s[k] !~ /[?,]/
        next if ! f(s, i, k-1)
        if t = f(s, k+1, j)
            max = t if t > 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

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