s = gets.chomp
n = gets.to_i
lr = 0
op = "+"
s.each_char do |c|
    if c == "+" || c == "*"
        op = c
    else
        if op == "+"
            lr += c.to_i
        else
            lr *= c.to_i
        end
    end
end
while s.include?("*")
    opi = s.index("*")
    l = opi - 1
    while s[l - 1] =~ /[0-9]/ && l > 0
        l -= 1
    end
    r = opi + 1
    while s[r + 1] =~ /[0-9]/ && r < s.length - 1
        r += 1
    end
    rep = (s[l..(opi - 1)].to_i * s[(opi + 1)..r].to_i).to_s
    s[l..r] = rep
end
ma = 0
s.each_char do |c|
    next if c == "+"
    ma += c.to_i
end
if n == lr
    puts "L" if n != ma
    puts "U" if n == ma
else
    puts "I" if n != ma
    puts "M" if n == ma
end