import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {

  val input = readLine.trim.toList
  val bob = readLine.trim.toInt
  val multiplicationFirst = input match {
    case m MultiplicationFirst Nil ⇒ m
    case _ ⇒ None
  }
  val left = input match {
    case l Left Nil ⇒ l
    case _ ⇒ ???
  }
  println(
    if (bob == multiplicationFirst && bob != left) 'M'
    else if (bob != multiplicationFirst && bob == left) 'L'
    else if (bob == multiplicationFirst && bob == left) 'U'
    else 'I'
  )

  object MultiplicationFirst {
    def unapply(str: List[Char]): Option[(Long, List[Char])] = {
      str match {
        case l Factor t ⇒
          t match {
            case '+':: (r MultiplicationFirst rest) ⇒ Some(l + r, rest)
            case Nil ⇒ Some(l, t)
            case _ ⇒ ???
          }
        case _ ⇒ ???
      }
    }
    private object Factor {
      def unapply(str: List[Char]): Option[(Long, List[Char])] = {
        str match {
          case l Number t ⇒ Some(takeAll(t, l))
          case _ ⇒ None
        }
      }
    }
    @tailrec private[this] def takeAll(str: List[Char], left: Long): (Long, List[Char]) = {
      str match {
        case '*'::(r Number rest) ⇒ takeAll(rest, left * r)
        case _ ⇒ (left, str)
      }
    }
  }
  object Left {
    def unapply(str: List[Char]): Option[(Long, List[Char])] = {
      str match {
        case l Number t ⇒ Some(takeAll(t, l), Nil)
        case _ ⇒ ???
      }
    }
    @tailrec private[this] def takeAll(str: List[Char], left: Long): Long = {
      str match {
        case '+'::(r Number rest) ⇒ takeAll(rest, left + r)
        case '*'::(r Number rest) ⇒ takeAll(rest, left * r)
        case Nil ⇒ left
        case _ ⇒ ???
      }
    }
  }
  object Number {
    def unapply(str: List[Char]): Option[(Long, List[Char])] = {
      str.span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (n, t) ⇒ Some(n.foldLeft(0L){(a, b) ⇒ a * 10 + b.asDigit }, t)
      }
    }
  }
  implicit class Extension[T](val value: T) extends AnyVal {
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
    @inline def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
