import datetime a, b = map(int, input().split()) a %= 12 t = a * 3600 + b * 60 ans = 1000000 for i in range(12): ans = min(ans, (i * 3600 + i * 3600 // 11 - t) % 86400) print(ans)