l=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
y=["1","0","X","9","8","7","6","5","4","3","2"]
sum=0
if(len(s)>=18):
for i in range(0,len(s)-1):
sum+=int(s[i])*l[i]
if(sum!=0):
if y[sum%11].lower()==s[17].lower():
print("合法")
else:
print("不合法")
else:
print("不合法")