a,b = map(int,input().split()) if a >= 12: a -= 12 x = a*30+0.5*b y = b*6 if x >= y: dif = x-y else: dif = 360-(y-x) ans = dif*60/5.5 print(int(ans))