A, B = map(int, input().split()) eps = 1e-10 th1 = 30 * A + 0.5 * B if th1 >= 360: th1 -= 360 th2 = 6 * B if th2 >= 360: th2 -= 360 if abs(th1 - th2) < eps: print(0) elif th1 < th2: d = 360 - th2 + th1 t = d / 5.5 * 60 print(int(t)) else: d = th1 - th2 t = d / 5.5 * 60 print(int(t))