#include <stdio.h>
int isMultFirst(char* s, int n)
{
    char stack[20], *p;
    int sp=0, res=0;
    for(p=s;*p;++p) {
        if (*p=='*') {
            int t=stack[--sp]*(*++p-'0');
            stack[sp++]=t;
        }
        else if (*p!='+') {
            stack[sp++]=*p-'0';
        }
    }
    while (sp>1) {
        int a=stack[--sp];
        int b=stack[--sp];
        stack[sp++]=a+b;
    }
    return stack[0]==n;
}
int isLeftToRight(char* s, int n)
{
    int res=s[0]-'0';
    char* p;
    for(p=s+1;*p;p+=2) {
        if (*p=='+')
            res=res+(*(p+1))-'0';
        else
            res=res*((*(p+1))-'0');
    }
    return res==n;
}
int main(void)
{
    char s[20];
    int n;
    while (~scanf("%s%d", s, &n)) {
        int multi=isMultFirst(s, n);
        int ltor=isLeftToRight(s, n);
        puts(multi && ltor ? "U" : multi ? "M" : ltor ? "L" : "I");
    }
    return 0;
}