These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.

He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.

Find the earliest time when Arkady can insert the takeoff.


-----Input-----

The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.

Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.


-----Output-----

Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.


-----Examples-----
Input
6 60
0 0
1 20
3 21
5 0
19 30
23 40

Output
6 1

Input
16 50
0 30
1 20
3 0
4 30
6 10
7 50
9 30
11 10
12 50
14 30
16 10
17 50
19 30
21 10
22 50
23 59

Output
24 50

Input
3 17
0 30
1 0
12 0

Output
0 0



-----Note-----

In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.

In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.

In the third example Arkady can insert the takeoff even between the first landing.

Difficulty: interview

Starter code:

Solutions:
n, s = [int(x) for x in input().split()]

ts = []
for _ in range(n):
    h, m = [int(x) for x in input().split()]
    ts.append(h * 60 + m)

if ts[0] >= s + 1:
    print(0, 0)
    return

diffs =  [y - x for x, y in zip(ts, ts[1:])]

for i, diff in enumerate(diffs):
    if diff >= 2 * s + 2:
        break
else:
    i = len(ts) - 1

t = ts[i] + s + 1
print(t // 60, t % 60)


a, b = map(int, input().split())
c = [-b-1]
for i in range(a):
    k, l = map(int, input().split())
    c.append(k*60+l)
c.append(10000000000000000)
for i in range(a+1):
    if c[i+1]-c[i]> 2*b+1:
        u = c[i]+b+1
        print(u//60, u%60)
        break

n,s = list(map(int,input().split()))
a = []
for i in range(n):
    h,m = list(map(int,input().split()))
    a.append(60*h + m)
a.append(10000000000)
if a[0] > s:
    print(0,0)
else:
    for i in range(n):
        if (a[i+1]-a[i] > 2*s+1):
            print((a[i]+s+1)//60,(1+a[i]+s)%60)
            break


def run():
    n, s = [int(x) for x in input().split()]
    d = [[int(x) for x in input().split()] for _ in range(n)]

    first = d[0]
    first = first[0]*60+first[1]
    if first >= s+1:
        print(0, 0)
        return

    for i in range(n-1):
        lft, rgt = d[i], d[i+1]
        lft = lft[0]*60+lft[1]
        rgt = rgt[0]*60+rgt[1]

        if rgt - lft >= (s+1)*2:
            ans = lft+s+1
            print(ans//60, ans%60)
            return

    rgt = d[-1]
    rgt = rgt[0] * 60 + rgt[1]
    ans = rgt+s+1
    print(ans // 60, ans % 60)


run()

def main():
    [n, s] = [int(i) for i in input().split()]
    times = []
    for i in range(n):
        [hour, minute] = [int(i) for i in input().split()]
        times.append(hour * 60 + minute)
    ans = earliest(times, s)
    hour = ans // 60
    minute = ans % 60
    print(hour, minute)
def earliest(times, s):
    n = len(times)
    if times[0] >= s + 1:
        return 0
    for i in range(n - 1):
        bef = times[i]
        aft = times[i + 1]
        if aft - bef >= 2 * s + 2:
            return bef + s + 1
    return times[n - 1] + s + 1
def __starting_point():
    main()

__starting_point()

n,s = map(int, input().split())
a,b = map(int, input().split())
if a*60+b>=s+1:
    print(0,0)
else:
    X = 0
    for i in range(n-1):
        c,d = map(int, input().split())
        if c*60+d - (a*60+b) >= 2*s+2:
            M = a*60+b+1+s
            print(M//60,M%60)
            X = 1
            break
        else:
            a,b = c,d
    if X==0:
        M = a*60+b+1+s
        print(M//60,M%60)

a = True
n, s = [int(x) for x in input().split()]
ph, pm = [int(x) for x in input().split()]

if ph*60 + pm >= s+1:
    print(0, 0)
    a = False
    return
for x in range(n - 1):
    h, m = [int(x) for x in input().split()]
    if h*60+m >= ph*60+pm + 2 + 2 * s:
        print((ph*60+pm+s+1) // 60, (ph*60+pm+s+1) % 60)
        a = False
        break
    else:
        ph = h
        pm = m
if a:
    print((ph*60+pm+s+1) // 60, (ph*60+pm+s+1) % 60)


# python3

def readline(): return tuple(map(int, input().split()))


def readlines(count):
    while count:
        count -= 1
        yield readline()


def main():
    n, s = readline()
    shedule = [h*60 + m for (h, m) in readlines(n)]

    shedule.append(float('inf'))
    prev = -s

    for time in shedule:
        if prev + s < time - s:
            print(*divmod(prev + s, 60))
            break
        prev = time + 1



main()


n,s=map(int,input().split())
t=[]
for i in range(n):
	h,m=map(int,input().split())
	t.append(60*h+m)
x,y=0,0
if t[0]<s+1:
	for i in range(n-1):
		if t[i+1]-t[i]>=2*s+2:
			x=t[i]+s+1
			break
	if x==0:
		x=t[n-1]+s+1
y=x%60
x=x//60
print(x,y)

n,s=map(int,input().split())
time=[0]*n
for i in range(n):
  h,m=map(int,input().split())
  time[i]=h*60+m

gogo=0
if time[0]-1-gogo>=s:
  print(0,0)
  return

fail=True
for i in range(n-1):
  gogo=time[i]+1+s
  if time[i+1]-gogo-1>=s:
    ans=gogo
    fail=False
    break

if fail: gogo=time[-1]+s+1 
hour=gogo//60
min=gogo%60
print(hour,min)

n, s = [int(w) for w in input().split()]

r = 0

for _ in range(n):
    h, m = [int(w) for w in input().split()]
    t = 60*h+m
    if t > r+s:
        break
    r = t+s+1

print(r//60, r%60)


num_landings, min_interval = (int(x) for x in input().split())
landings = [[int(x) for x in input().split()] for _ in range(num_landings)]
landings_in_minutes = [-min_interval - 1] + [60*clock[0] + clock[1] for clock in landings] + [float('inf')]

for left_landing, right_landing in zip(landings_in_minutes[:-1], landings_in_minutes[1:]):
    if left_landing + 2*min_interval + 2 <= right_landing:
        takeoff = left_landing + 1 + min_interval
        break

takeoff_hours = takeoff // 60
takeoff_mins = takeoff % 60
print(takeoff_hours, takeoff_mins)
        




def to_minutes(h, m):
    return h * 60 + m
def to_retard(m):
    return divmod(m, 60)

n, s = [int(i) for i in input().split(' ')]

takeoffs = []
for i in range(n):
    takeoff_time = to_minutes(*([int(i) for i in input().split(' ')]))
    takeoffs.append(takeoff_time)

def solve():
    if takeoffs[0] > s:
        return 0
    for i in range(n-1):
        if takeoffs[i+1] - takeoffs[i] - 1 >= 2*s +1:
            return takeoffs[i] + s + 1
    return takeoffs[-1] + s + 1

print(*to_retard(solve()))


n, s = list(map(int, input().split()))
a = []
ind = True
for i in range(n):
	x, y = list(map(int, input().split()))
	time = (60 * x) + y
	if len(a) == 0 and time >= s + 1 and ind:
		print(0, 0)
		ind = False
	elif len(a) > 0 and ind:
		last = a[len(a) - 1]
		if time - last >= (2 * s) + 2:
			y = last + s + 1
			print(y // 60, y % 60)
			ind = False
	a.append(time)
#print(a)	
if ind:
	y = a[len(a) - 1] + s + 1
	#print(y)
	print(y // 60, y % 60)		



import sys
n, s = [int(x) for x in input().split()]
h1,m1 = [int(x) for x in input().split()]
if h1*60+m1>=s+1:
    print(0, 0)
    return
for i in range(n-1):
    h2, m2 = [int(x) for x  in input().split()]
    if h2*60+m2>=h1*60+m1+2+s*2:
        z= h1*60+m1+1+s
        print(z//60, z%60)
        return
    h1=h2
    m1=m2

z=h1*60+m1+1+s
print(z//60, z%60)

        


n, s = input().split(' ')
n, s = int(n), int(s)
rst = [-1, -1]
last = [0, 0]
h, m = input().split(' ')
h, m = int(h), int(m)
if (h - last[0]) * 60 + (m - last[1]) >= s + 1:
    rst = [0, 0]
else:
    last = [h, m]
    for i in range(1, n):
        h, m = input().split(' ')
        h, m = int(h), int(m)
        if (h - last[0]) * 60 + (m - last[1]) >= 2 * s + 2:
            rst = [last[0] + s // 60, last[1] + s % 60 + 1]
            break
        last = [h, m]
if rst == [-1, -1]:
    rst = [last[0] + s // 60, last[1] + s % 60 + 1]
if rst[1] >= 60:
    rst[0] += 1
    rst[1] -= 60
print(rst[0], rst[1])


n, s = map(int, input().split())
chegadas = []
for _ in range(n):
    h, m = map(int, input().split())
    chegadas.append(h*60+m)
pos = -1

if chegadas[0] > s:
    print(0, 0)
else:
    for i in range(n-1):
        if chegadas[i+1] - chegadas[i] > ((s*2) + 1):
            pos = i
            break

    t = chegadas[pos] + s + 1
    h, m = int(t / 60), t % 60
    print(h, m)

n, s = map(int, input().split(' '))
l = list()
for i in range(n):
    a, b = map(int, input().split(' '))
    l.append(a * 60 + b)
if l[0] - s >= 1:
    print(0, 0)
else:
    for i in range(n - 1):
        t = l[i + 1] - l[i] - 1 - 2 * s
        if t >= 1:
            tt = l[i] + 1 + s
            h, m = tt // 60, tt % 60
            print(h, m)
            break
    else:
        tt = l[-1] + 1 + s
        h, m = tt // 60, tt % 60
        print(h, m)

n, s = map(int, input().split())
a = []
for _ in range(n):
    h, m = map(int, input().split())
    a.append((h,m))
b = [h*60+m for (h,m) in a]
c = -1
if b[0] > s:
    print(0,0)
else:
    for i in range(n-1):
        if b[i+1]-b[i] > s*2+1:
            c = i
            break
    r = ((b[c]+s+1) // 60,(b[c]+s+1) % 60)
    print(r[0],r[1])

n,s = list(map(int,input().split(' ')))
v0 = 0
fl = False



for i in range(n):
  h,m = list(map(int,input().split(' ')))
  v = h*60+m
  if i==0 and (v-1) >= s:
    m2 = 0
    h2 = 0
    fl = True
    break
  elif (v-v0-2) // 2 >= s:
    v2 = v0+s+1
    m2 = (v2)%60
    h2 = (v2)//60
    fl = True
    break
  else:
    v0 = v
if fl:
  print(h2,m2)
else:
  m2 = (v0+s+1)%60
  h2 = (v0+s+1)//60
  print(h2,m2)


n, s = [int(x) for x in input().split(" ")]

last = 0
found = False
rng = 2 * s + 2

first = s + 1

f = False

ff = False

for _ in range(n):

    h, m = [int(x) for x in input().split(" ")]
    x = h * 60 + m
    if not f:
        if abs(x - last) >= first:
            found = True
            ff = True
        else:
            last = x
    elif not found:
        if abs(x - last) >= rng:
            found = True
        else:
            last = x
    f = True


# if found:
if ff:
    print(0, 0)
else:
    res = last + s + 1
    print("{} {}".format(res // 60, res % 60))
# else:
#     print()


rd = lambda: list(map(int, input().split()))
n, s = rd()
a = [- s - 1]
for _ in range(n):
    h, m = rd()
    a.append(h * 60 + m)
x = 0
for i in range(1, len(a)):
    if a[i - 1] + s + 1 <= x <= a[i] - s - 1:
        break
    x = a[i] + s + 1
print(x // 60, x % 60)


def preobr(s):
    h, m = list(map(int,s.split()))
    return h * 60 + m


n, s = list(map(int,input().split()))
t = preobr(input())
s += 1
fl = False
if t >= s:
    res = 0
    fl = True
for i in range(n - 1):
    new_t = preobr(input())
    if fl:
        continue
    if new_t - t >= 2 * s:
        res = t + s
        fl = True
    else:
        t = new_t
if not fl:
    res = t + s
print(res // 60, res % 60)