#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<stack> using namespace std; char str[20]; int main() { int n; int len,ans; int s1,s2; int i,j,k; while(scanf("%s",str)!=EOF) { s1=0;s2=0; scanf("%d",&ans); stack<int> q; len=strlen(str); for(i=0;i<len;i++) { if(i%2==0) { q.push(str[i]-'0'); } else { if(str[i]=='*') { i++; int temp=q.top(); q.pop(); temp=temp*(str[i]-'0'); q.push(temp); } } } while(!q.empty()) { s1+=q.top(); q.pop(); } //if(q.empty()) printf("dddddddd "); for(i=0;i<len;i++) { if(i%2==0) { s2+=(str[i]-'0'); } else { if(str[i]=='*') { i++; s2*=(str[i]-'0'); } } } //printf("dddddd "); if(s1==ans&&s1!=s2) printf("M "); else if(s2==ans&&s1!=s2) printf("L "); else if(s1==ans&&s1==s2) printf("U "); else printf("I "); } return 0; }