def solve(h: int, m: int) -> tuple:
    while True:
        if h > 23:
            h = 0
        while True:
            if m > 59:
                m = 0
                break
            a, b = h // 10, h % 10
            c, d = m // 10, h % 10
            if a * 10 + c < 24 and b * 10 + d < 60:
                return (h, m)
            m += 1
        h += 1


h, m = map(int, input().split())
print(*solve(h, m))
