def l str
    result = str[0].to_i
    ((str.length - 1) / 2).times{|i|
        result += str[i * 2 + 2].to_i if str[i * 2 + 1] == "+"
        result *= str[i * 2 + 2].to_i if str[i * 2 + 1] == "*"
    }
    result
end

def m str
    str.split("+").map{|x| l x}.inject(:+)
end

expression = gets.chomp
bob = gets.to_i

a = m(expression) == bob
b = l(expression) == bob
answer = "M"
answer = "L" if !a && b
answer = "U" if a && b
answer = "I" if !a && !b
puts answer
