// Aizu 1346: Miscalculation
// 2017.9.19 bal4u@uu

#include <stdio.h>

char buf[102], *p;

long long term()
{
	long long x = *p++ - '0';
	while (1) {
		if (*p == '*') p++;	else break;
		x *= *p++ - '0';
	}
	return x;
}

long long multiFirst()
{
	long long x = term();
	while (1) {
		if (*p == '+') p++; else break;
		x += term();
	}
	return x;
}

long long left2right()
{
	long long x;
	int y, op;
	
	x = *p++ - '0';
	while (*p) {
		op = *p++, y = *p++ - '0';
		if (op == '*') x *= y;
		else           x += y;
	}
	return x;
}

int main()
{
	int k;
	long long a;
	char *ans[4] = { "I", "M", "L", "U" };

	scanf("%s%lld", buf, &a); k = 0;
	p = buf; if (multiFirst() == a) k |= 1;
	p = buf; if (left2right() == a) k |= 2;
	puts(ans[k]);
	return 0;
}