A, B = map(int, input().split()) # Calculate the angles of the hour and minute hands hour_angle = A * 30 + B * 0.5 minute_angle = B * 6 # Compute the difference modulo 360 diff = (hour_angle - minute_angle) % 360 # Check if the difference is effectively zero considering floating-point precision epsilon = 1e-10 if diff < epsilon or (360 - diff) < epsilon: print(0) else: # Convert the difference to seconds x = int(diff * 2) # diff is a multiple of 0.5, so x is an integer seconds = (x * 60) // 11 print(seconds)