A, B = map(int, input().split()) # Calculate the angles of the hour and minute hands hour_angle = (A % 12) * 30 + B * 0.5 minute_angle = B * 6 # Compute the angle difference modulo 360 to get the smallest positive difference delta = (hour_angle - minute_angle) % 360 # Check if the hands are already aligned if abs(delta) < 1e-9: print(0) else: # Calculate the required time in minutes and convert to seconds t_minutes = delta / 5.5 total_seconds = t_minutes * 60 print(int(total_seconds))