void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.array;
  
  auto expr=readln.chomp.to!(char[]);
  int res; rd(res);

  auto n=expr.length;
  int[] a; a~=(expr[0]-'0');
  for(auto i=1; i<n; i+=2){
    if(expr[i]=='+') a~=(expr[i+1]-'0');
    else{
      auto bk=a.back; a.popBack;
      a~=(bk*(expr[i+1]-'0'));
    }
  }
  auto res1=sum(a);

  int res2=(expr[0]-'0');
  for(auto i=1; i<n; i+=2){
    if(expr[i]=='+') res2+=(expr[i+1]-'0');
    else res2*=(expr[i+1]-'0');
  }
  
  if(res1==res2 && res1==res) writeln("U");
  else if(res1==res) writeln("M");
  else if(res2==res) writeln("L");
  else writeln("I");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}