Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.

A time is considered lucky if it contains a digit '7'. For example, 13: 07 and 17: 27 are lucky, while 00: 48 and 21: 34 are not lucky.

Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh: mm.

Formally, find the smallest possible non-negative integer y such that the time representation of the time x·y minutes before hh: mm contains the digit '7'.

Jamie uses 24-hours clock, so after 23: 59 comes 00: 00.


-----Input-----

The first line contains a single integer x (1 ≤ x ≤ 60).

The second line contains two two-digit integers, hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).


-----Output-----

Print the minimum number of times he needs to press the button.


-----Examples-----
Input
3
11 23

Output
2

Input
5
01 07

Output
0



-----Note-----

In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.

In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.

Difficulty: interview

Starter code:

Solutions:
x=int(input())
h,m=list(map(int,input().split()))
def ok(mm):
  while mm<0: mm+=1440
  hh=mm//60
  mm=mm%60
  return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7
for y in range(999):
  if ok(h*60+m-y*x):
    print(y)
    return


def lucky(x):
    return (x % 10 == 7)
x = int(input())
h, m = list(map(int, input().split()))
t = 60 * h + m

ans = float('inf')
for hh in range(24):
    for mm in range(60):
        if lucky(hh) or lucky(mm):
            s = 60 * hh + mm
            while t < s:
                s -= 60 * 24

            r = t - s
            if r % x != 0:
                continue

            ans = min(ans,  r // x)

print(ans)


x=int(input())
line=input().split()
h=int(line[0])
m=int(line[1])
s=0
while (not m%10==7) and (not h%10==7):
    m-=x
    if m<0:
        m+=60
        h-=1
    if h<0:
        h+=24
    s+=1
print (s)


x = int(input())
hh, mm = [int(v) for v in input().split()]

ans = 0
while '7' not in ('%s%s' % (hh, mm)):
    ans += 1
    if x == 60:
        hh -= 1
    else:
        mm -= x
        if mm < 0:
            mm += 60
            hh -= 1
            if hh < 0:
                hh = 23

print(ans)


def lucky(a,b):
    return '7' in str(a)+str(b)
x = int(input())
t = 0
h,m = list(map(int,input().split()))
while not lucky(h,m):
    t+=1
    m -= x
    while m<0:
        m+=60
        h-=1
    h%=24
print(t)


def isLucky(t):
	if 7==t%10:
		return True
	if (t//60)%10==7:
		return True
	return False

x = int(input())
h,m = list(map(int,input().split()))
ct = h*60+m
ans = 0
while (not isLucky(ct)):
	ct = (ct-x)%(60*24)
	ans+=1
print(ans)


def nt(t):
    t = t % (60 * 24)
    return '7' in str(t // 60) + str(t % 60)

x = int(input())
h, m = [int(i) for i in input().split()]
t = h * 60 + m
ans = 0
while not nt(t):
    t = (t - x) % (60 * 24)
    ans += 1
print(ans)

x = int(input())
h,m = map(int, input().split())
ans = 0
while 1:
    if '7' in str(h) + str(m):
        break
    ans += 1
    if m >= x:
        m -= x
    else:
        m = 60 - (x-m)
        h -= 1
        if h == -1:
            h = 23
print(ans)

x = int(input())

h, m = [int(x) for x in input().split()]

for y in range(3600):
    t = h * 60 + m - x * y
    if t < 0:
        t += 60 * 24
    h_new = t // 60
    m_new = t % 60
    
    if '7' in str(h_new) + str(m_new):
        print(y)
        break


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
read = lambda: list(map(int, input().split()))


x = int(input())
hh, mm = read()
r = 0
while '7' not in str(mm) and '7' not in str(hh):
    mm -= x
    if mm < 0:
        hh -= 1
        mm += 60
    if hh < 0:
        hh = 23
    r += 1
print(r)


def lucky(hh, mm):
  if '7' in str(hh):
    return True
  if '7' in str(mm):
    return True
  return False

x = int(input())
h, m = map(int, input().split())
cnt = 0
while not lucky(h, m):
  m -= x
  if m < 0:
    m += 60
    h -= 1
  if h < 0:
    h += 24
  cnt += 1
 
print(cnt)

x = int(input())
hh, mm = map(int, input().split())
mins = hh * 60 + mm
ans = 0
while str(mins // 60).count('7') == 0 and str(mins % 60).count('7') == 0:
    mins -= x
    ans += 1
    if mins < 0:
        mins = 1440 + mins
print(ans)


def lucky(x, y):
    return '7' in str(x) + str(y)

def take(hour, minutes, time):
    minutes = minutes - time

    if minutes < 0:
        hour -= 1
        minutes += 60

    if hour < 0:
        hour += 24

    return hour, minutes


def __starting_point():
    x = int(input())
    hour, minutes = list(map(int, input().split()))

    total = 0
    while not lucky(hour, minutes):
        hour, minutes = take(hour, minutes, x)
        total += 1

    print(total)

__starting_point()

x = int(input())
n, m = list(map(int, input().split()))
a = 0
while (n % 10 != 7 and n // 10 != 7 and m % 10 != 7 and m // 10 != 7):
    m -= x
    if m < 0:
        m += 60
        n -= 1
        if n < 0:
            n  += 24
    a += 1
print(a)


x = int(input())
h, m = input().split()
if '7' in h + m:
	print(0)
else:
	res = 0
	while not '7' in h + m:
		m = str(int(m) - x)
		if m[0] == '-':
			m = str(60 + int(m))
			h = str(int(h) - 1)
			if h[0] == '-':
				h = str(24 + int(h))
		res += 1
	print(res)



def dst(a, b):
	if (a <= b):
		return b - a
	return b - a + 60 * 24

x = int(input())
h, m = map(int, input().split())
# print(h, m)
cur = 60 * h + m
ans = 10**9
for H in range(24):
	for M in range(60):
		if (str(H) + str(M)).count("7"):
			if (dst(H * 60 + M, cur) % x == 0):
				ans = min(ans, dst(H * 60 + M, cur) // x)
print(ans)

from sys import stdin, stdout

x = int(stdin.readline())
a, b = list(map(int, stdin.readline().split()))

time = a * 60 + b
for i in range(10 ** 6):
    t = time - i * x
    
    if t < 0:
        t += 24 * 60
        time += 24 * 60
    
    if '7' in str(t // 60) + str(t % 60):
        stdout.write(str(i))
        break


x=int(input())
arr=list(map(int,input().strip().split(' ')))
h=arr[0]
m=arr[1]
cnt=0
while(True):
     s=str(h)
     ss=str(m)
     if('7' in s or '7' in ss):
          break
     else:
          cnt+=1
          
          if(m-x<0):
               if(h-1<0):
                    h=23
               else:
                    h-=1
               m=60+m-x
          else:
               m=m-x
print(cnt)

x = int(input())
h, m = list(map(int, input().split()))
t = 60 * h + m
def check(t):
    h = str(t // 60)
    m = str(t % 60)
    if '7' in h + m:
        return True
    return False
an = 0
while not check(t):
    t -= x
    an += 1
    if t < 0:
        t = 24 * 60 + t
print(an)


x = int(input())
hh, mm = list(map(int, input().split()))
i= 0
while(True):
    if str(hh).find('7') >= 0 or str(mm).find('7') >= 0:
        break
    mm -= x
    if mm < 0:
        mm %= 60
        hh -= 1
        hh %= 24
    i+=1
print(i)


def test(x):
	return '7' in str(x)

x = int(input())
h,m=[int(i)for i in input().split()]
ans = 0
while (not test(h)) and (not test(m)):
	if m - x < 0:
		if h == 0:
			h = 23
		else: h -= 1   
		m = m - x + 60 
	else:m -= x	
	ans += 1
print(ans)	


x = int(input())

hh, mm = map(int, input().split())

def ch(hh, mm):
    return '7' in str(hh) or '7' in str(mm)

count = 0
while not ch(hh, mm):
    count += 1
    if mm >= x:
        mm -= x
    else:
        hh -= 1
        mm -= x - 60
    if hh < 0:
        hh = 23
print(count)

x = int(input())
h,m = map(int,input().split())
ans = 0
while (h % 10 != 7) and (m % 10 != 7):
	if m - x >= 0:
		m -= x
	else:
		temp = x - m
		m = 60 - temp
		if h - 1 >= 0:
			h -= 1
		else:
			h = 23
	ans += 1
	# print(':'.join([str(h),str(m)]))
print(ans)



x = list(map(int, input().strip().split()))[0]
h, m = list(map(int, input().strip().split()))


count = 0

while True:
    a = str(h)
    b = str(m)
    if '7' in a:
        break
    if '7' in b:
        break
    count += 1
    m -= x
    if m < 0:
        h -= 1
        m += 60
    if h < 0:
        h += 24

print(count)

x = int(input().strip())
first_line = input().strip()
hh = first_line.split()[0]
mm = first_line.split()[1]

num_snooze = 0

while '7' not in hh and '7' not in mm:
    h = int(hh)
    m = int(mm)

    m -= x

    if m < 0:
        m += 60
        h -= 1
        if h < 0:
            h += 24
            
    num_snooze += 1

    hh = str(h)
    mm = str(m)

print(num_snooze)