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.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation

Complete search


Solutions:
(x, y) = (int(input()), 0)
(h, m) = map(int, input().split())
t = h * 60 + m
while True:
	(h, m) = divmod(t, 60)
	if h % 10 == 7 or m % 10 == 7:
		break
	t = (t - x) % 1440
	y += 1
print(y)


x = int(input())
(hh, mm) = map(int, input().split())
ans = 0
while 1:
	if hh / 10 == 7 or hh % 10 == 7 or mm / 10 == 7 or (mm % 10 == 7):
		break
	ans += 1
	mm -= x
	if mm < 0:
		mm = 60 + mm
		hh -= 1
	if hh < 0:
		hh = 23
print(ans)


ini = lambda : int(input())
inl = lambda : list(map(int, input().split()))
x = ini()
(hh, mm) = inl()
import datetime
wake = datetime.datetime(2000, 1, 1, hh, mm)
mins = datetime.timedelta(minutes=x)
c = 0
while '7' not in wake.strftime('%H%M'):
	wake -= mins
	c += 1
print(c)


def judge(s):
	for i in s:
		if i == '7':
			return True
	return False

def main():
	x = int(input())
	l = input().split()
	h = int(l[0])
	hh = h
	m = int(l[1])
	mm = m
	while True:
		if judge(str(m)) or judge(str(h)):
			break
		m -= x
		if m < 0:
			m += 60
			h -= 1
	print(((hh - h) * 60 + (mm - m)) // x)
main()


x = int(input())
s = input().split(' ')
(a, b) = (int(s[0]), int(s[1]))
T = 0

def has7(x):
	if x % 10 == 7:
		return 1
	else:
		return 0
while True:
	if has7(a) or has7(b):
		break
	b = b - x
	if b < 0:
		b = b + 60
		a = a - 1
		if a < 0:
			a = a + 24
	T = T + 1
print(T)


x = int(input())
(a, b) = map(int, input().split())
y = 0
while '7' not in str(a) + str(b):
	z = b + a * 60 + 1440
	z -= x
	z %= 1440
	a = z // 60
	b = z % 60
	y += 1
print(y)


def main():
	minute: int = int(input())
	count: int = 0
	myTime: str = input()
	hh: int = int(myTime[0:myTime.find(' '):1])
	mm: int = int(myTime[myTime.find(' ') + 1:len(myTime):1])
	if myTime.find('7') == -1:
		while (str(hh) + str(mm)).find('7') == -1:
			hh -= 0 if mm - minute >= 0 else 1
			hh += 0 if hh >= 0 else 24
			mm += -minute if mm - minute >= 0 else 60 - minute
			count += 1
	print(count)
	return True
main()


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)


n = int(input())
(h, m) = [int(i) for i in input().split()]
if h % 10 == 7 or m % 10 == 7 or h // 10 == 7 or (m // 10 == 7):
	print(0)
else:
	c = 0
	while True:
		m -= n
		c += 1
		if m < 0:
			m += 60
			h -= 1
			if h < 0:
				h = 23
		if h % 10 == 7 or m % 10 == 7 or h // 10 == 7 or (m // 10 == 7):
			print(c)
			break


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
x = ii()
(hh, mm) = mi()
ans = 0
while '7' not in str(hh) and '7' not in str(mm):
	if mm - x < 0:
		hh -= 1
		if hh < 0:
			hh = 23
		mm = (mm - x) % 60
	else:
		mm -= x
	ans += 1
print(ans)


n = int(input())
(h, m) = map(int, input().split())
ans = 0
while True:
	s = str(h) + str(m)
	if '7' in s:
		break
	else:
		m -= n
		if m < 0:
			m = 60 + m
			h -= 1
			ans += 1
		else:
			ans += 1
print(ans)


x = int(input())
(h, m) = map(int, input().split())
lucky = [7, 17, 27, 37, 47, 57]
y = 0
while not (h in lucky or m in lucky):
	m -= x
	if m < 0:
		h -= 1
		m = 60 + m
	if h < 0:
		h = 24 + h
	y += 1
print(y)


import datetime as dt
x = int(input())
(hh, mm) = map(int, input().split())
wake_time = dt.datetime.now().replace(hour=hh, minute=mm, second=0, microsecond=0)
delta = dt.timedelta(minutes=x)
i = 0
while True:
	if '7' in wake_time.strftime('%H:%M'):
		break
	wake_time = wake_time - delta
	i += 1
print(i)


x = int(input())
(hh, mm) = map(int, input().split())
t = 60 * hh + mm
for y in range(399):
	(hh, mm) = divmod((t - x * y) % 1440, 60)
	if '7' in str(hh) + str(mm):
		print(y)
		break


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


x = int(input())
(h, m) = map(int, input().split())
count = 0
while '7' not in str(h) + str(m):
	m -= x
	while m < 0:
		m += 60
		h -= 1
	while h < 0:
		h += 24
	count += 1
print(count)


x = int(input())
(h, m) = input().split()
h = int(h)
m = int(m)

def check(hours, minutes):
	if hours // 10 == 7 or hours % 10 == 7 or minutes % 10 == 7:
		return 1
	else:
		return 0
i = 0
while check(h, m) != 1:
	i += 1
	m = m - x
	if m < 0:
		h = h - 1
		m = m + 60
	if h < 0:
		h = h + 24
print(i)


import sys, os

def has7(i):
	if i % 10 == 7:
		return 1
	i /= 10
	if i % 10 == 7:
		return 1
	return 0

def main():
	n = int(sys.stdin.readline())
	(h, m) = map(int, sys.stdin.readline().split())
	i = 0
	while 1:
		if has7(h):
			break
		if has7(m):
			break
		i += 1
		m -= n
		if m < 0:
			m += 60
			h -= 1
		if h < 0:
			h += 24
	print(i)
main()


from sys import stdin, stdout
Input = []
Input = [stdin.readlines()]
Input = Input[0]
Input = [x.split(' ') for x in Input]
x = int(Input[0][0])
hh = int(Input[1][0])
mm = int(Input[1][1])
for y in range(1000):
	currenttime = hh * 60 + mm
	alarm = (currenttime - x * y) % 1440
	hh1 = int(alarm / 60)
	mm1 = alarm - hh1 * 60
	if '7' in str(hh1) + str(mm1):
		stdout.write(str(y))
		break


x = int(input())
(a, b) = map(int, input().split())
ans = 0

def isLucky(h, m):
	if '7' in str(h) or '7' in str(m):
		return True
	return False

def sub(h, m, x):
	if m > x:
		return (h, m - x)
	else:
		m -= x
		while m < 0:
			m += 60
			h -= 1
		return (h % 24, m)
while not isLucky(a, b):
	(a, b) = sub(a, b, x)
	ans += 1
print(ans)


x = int(input())
(i, j) = map(int, input().split())

def toMinutes(timeList):
	return timeList[0] * 60 + timeList[1]

def toTime(minutes):
	(h, m) = divmod(minutes, 60)
	(d, h) = divmod(h, 24)
	return [h, m]

def has7(timeList):
	for j in timeList:
		while j != 0:
			if j % 10 == 7:
				return True
			else:
				j = j // 10
	return False
counter = 0
while True:
	if has7(toTime(toMinutes([i, j]) - x * counter)):
		print(counter)
		break
	else:
		counter += 1


x = int(input())
(a, b) = map(int, input().split(' '))
c = {7: 1, 17: 1, 27: 1, 37: 1, 47: 1, 57: 1}
jam = 0
z = b
while True:
	try:
		if c[z] == 1:
			print(jam)
			break
	except:
		try:
			if c[a] == 1:
				print(jam)
				break
		except:
			jam += 1
			z = z - x
			if z < 0:
				z = 60 + z
				a -= 1
				if a < 0:
					a = 23


import sys
x = int(input())
(h, m) = input().split()
h = int(h)
m = int(m)
count = 0
while m % 10 != 7 and h % 10 != 7:
	count = count + 1
	m = m - x
	if m < 0:
		h = h - 1
		m = 60 + m
	if h < 0:
		h = 23
print(count)


x = int(input())
(hh, yy) = map(int, input().split())
snoozes = 0
while not '7' in str(hh) + str(yy):
	if yy - x < 0:
		yy = 60 + yy - x
		hh -= 1
		if hh < 0:
			hh = 23
	else:
		yy -= x
	snoozes += 1
print(snoozes)


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)


x = int(input())
t = input().split()
(h, m) = (int(t[0]), int(t[1]))
i = 0
while True:
	if '7' in str(h) or '7' in str(m):
		print(i)
		exit(0)
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
	i += 1


minutes = int(input())
hours_of_day = 24
minutes_of_hour = 60
desired_time = input().split()
time_dict = {'hour': desired_time[0], 'minutes': desired_time[1]}
happy_digit = '7'
if happy_digit in time_dict.get('hour') or happy_digit in time_dict.get('minutes'):
	print(0)
else:
	count_tries = 0
	while all([happy_digit not in time_dict.get('hour'), happy_digit not in time_dict.get('minutes')]):
		t = int(time_dict.get('minutes')) - minutes
		if t < 0:
			t = minutes_of_hour - abs(t)
			h = int(time_dict.get('hour')) - 1
			time_dict['hour'] = str(h)
		time_dict['minutes'] = str(t)
		count_tries = count_tries + 1
	print(count_tries)


x = int(input())
(h, m) = map(int, input().split(' '))
(orig_h, orig_m) = (h, m)
counter = 0

def isLucky(h, m):
	return '7' in str(h) or '7' in str(m)

def next_time(h, m, x):
	m -= x
	if m < 0:
		m = 60 + m
		h -= 1
	if h < 0:
		h = 24 + h
	return (h, m)
while True:
	if isLucky(h, m):
		if orig_h < h:
			orig_h += 24
		print((orig_h * 60 + orig_m - (h * 60 + m)) // x)
		break
	(h, m) = next_time(h, m, x)


n = int(input())
(h, m) = map(int, input().split())
count = 0
txt = '{}:{}'
while '7' not in txt.format(h, m):
	m -= n
	if m < 0:
		h -= 1
		m += 60
	if h < 0:
		h = 23
	count += 1
print(count)


t = int(input())
(h, m) = map(int, input().split())
if '7' in str(h) or '7' in str(m):
	print('0')
else:
	c = 0
	while 1:
		if '7' in str(h) or '7' in str(m):
			print(c)
			break
		elif t >= m:
			x = t - m
			if x == 0:
				m = 0
			else:
				m = 59 - (x - 1)
				h -= 1
			c += 1
		else:
			m = m - t
			c += 1


x = int(input())
(hh, mm) = map(int, input().split())
ans = 0

def is_0(hh):
	if hh == 0:
		return True
	else:
		return False

def has7(n):
	while n > 0:
		if n % 10 == 7:
			return True
		n = n / 10
i = mm
while True:
	if has7(mm) or has7(hh):
		break
	if mm >= x:
		mm -= x
	else:
		mm = 60 - (x - mm)
		if is_0(hh):
			hh = 23
		else:
			hh -= 1
	ans += 1
print(ans)


t = int(input())
(n, m) = input().split()
(p, k) = (int(n), int(m))
d = 0
s = 0
l = 0
while d != 1:
	if k > 10:
		if str(k)[0] == '7' or str(k)[1] == '7':
			if s % t == 0:
				print(s // t)
				l = 1
				d = 1
				break
	elif k < 10:
		if str(k)[0] == '7':
			if s % t == 0:
				print(s // t)
				l = 1
				d = 1
				break
	if p > 10:
		if str(p)[0] == '7' or str(p)[1] == '7':
			if l == 0:
				if s % t == 0:
					print(s // t)
					l = 1
					d = 1
					break
	elif p < 10:
		if str(p)[0] == '7':
			if l == 0:
				if s % t == 0:
					print(s // t)
					l = 1
					d = 1
					break
	if k != 0:
		k = (k - 1) % 60
	elif k == 0:
		k = 59
		p = (p - 1) % 24
	elif p == 0 and k == 0:
		p = 23
		k = 59
	s += 1


import sys
x = int(input())
(hh, mm) = input().split(' ')
hh = int(hh)
mm = int(mm)
cnt = 0
while 1:
	s = set(str(str(hh) + str(mm)))
	if '7' in s:
		break
	elif mm < x:
		r = x - mm
		mm = 60 - r
		if hh == 0:
			hh = 23
		else:
			hh -= 1
	else:
		mm -= x
	cnt += 1
print(cnt)


x = int(input())
i2 = input().split()
if int(i2[0]) % 10 == 7 or int(i2[1]) % 10 == 7:
	print(0)
else:
	h = int(i2[0])
	m = int(i2[1])
	count = 0
	flag = 0
	while True:
		while m >= 0:
			flag = 1
			if m % 10 == 7 or h % 10 == 7:
				break
			else:
				m = m - x
				count += 1
		if flag == 0:
			count += 1
		if h % 10 == 7 or m % 10 == 7:
			break
		h = (h - 1) % 24
		m = m + 60
	print(count)


x = int(input())
(hh, mm) = map(int, input().split())
answer = 0
while hh % 10 != 7 and mm % 10 != 7:
	if mm < x:
		diff = x - mm
		hh -= 1
		if hh < 0:
			hh = 23
		mm = 60 - diff
	else:
		mm -= x
	answer += 1
print(answer)


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)


import math, sys

def dead():
	sys.stdout.write('-1')
	sys.exit()
debug = 0
if debug:
	f = open('input.txt', 'r')
	input = f.readline

def main():
	x = int(input())
	(h, m) = map(int, input().split())
	ans = 0
	while not '7' in str(h) and (not '7' in str(m)):
		m -= x
		ans += 1
		if m < 0:
			m = 60 + m
			h -= 1
		if h < 0:
			h = 23
	print(ans)
main()


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)
		exit(0)


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

def countDown(x):
	global hh, mm
	mm -= x
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24

def check_lucky(hh, mm):
	return '7' in str(hh) + str(mm)
count = 0
while not check_lucky(hh, mm):
	countDown(interval)
	count += 1
print(count)


def che(x):
	a = x // 10
	b = x % 10
	if a == 7 or b == 7:
		return 1
	else:
		return 0

def check(x):
	a = x // 60
	b = x % 60
	if che(a) or che(b):
		return 1
	else:
		return 0
k = int(input())
(a, b) = map(int, input().split())
x = a * 60 + b
i = 0
while 1:
	if x < 0:
		x += 1440
	if check(x):
		break
	x -= k
	i += 1
print(i)


x = int(input())
(h, m) = map(int, input().split())
f = 0
if '7' in str(h) + str(m):
	print(f)
else:
	k = h * 60 + m
	s = str(k // 60).rjust(2, '0') + str(k - h * 60).rjust(2, '0')
	while '7' not in s:
		if k - x < 0:
			k = 23 * 60 + (60 - (x - k))
			s = str(k // 60).ljust(2, '0') + str(k - k // 60 * 60).ljust(2, '0')
			f += 1
		else:
			k -= x
			s = str(k // 60).ljust(2, '0') + str(k - k // 60 * 60).ljust(2, '0')
			f += 1
	print(f)


s = int(input())
(h, m) = input().split()
(hh, mm) = [int(h), int(m)]
ns = 0
while True:
	if '7' in h or '7' in m:
		break
	mm -= s
	if 0 > mm:
		hh -= 1
		if hh == -1:
			hh = 23
		mm = 60 + mm
	ns += 1
	h = str(hh)
	m = str(mm)
print(ns)


x = int(input())
(hh, mm) = list(map(lambda k: int(k), input().split()))

def has7(num):
	return '7' in str(num)

def solve1(x, hh, mm):
	count = 0
	while True:
		if has7(hh) or has7(mm):
			print(count)
			return
		mm -= x
		if mm < 0:
			mm += 60
			hh -= 1
		if hh < 0:
			hh += 24
		count += 1
	return -1
solve1(x, hh, mm)


n = int(input())
line = input().split()
a = int(line[0])
b = int(line[1])
i = 0
while a % 10 != 7 and b % 10 != 7:
	b -= n
	i += 1
	if b < 0:
		b += 60
		a -= 1
	if a < 0:
		a += 24
print(i)


x = int(input())
l = [int(a) for a in input().split()]
n = 0
b = l[1]
if (l[1] - 7) % 10 == 0 or (l[0] - 7) % 10 == 0:
	print('0')
else:
	a = 60 * l[0] + l[1]
	a0 = a
	while a - x > 0:
		a = a - x
		n += 1
		if (a - 7) % 10 == 0 or int(a / 60) == 7 or int(a / 60) == 17:
			break
	if a - x <= 0:
		a = 1440 + a
		while a > a0:
			a = a - x
			n += 1
			if (a - 7) % 10 == 0 or int(a / 60) == 7 or int(a / 60) == 17:
				break
	print(n)


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())
(hh, mm) = map(int, input().split())
ans = 0
mm += hh * 60
while '7' not in str(mm // 60) + str(mm % 60):
	mm = (mm - x) % 1440
	ans += 1
print(ans)


x = int(input())
(h, m) = map(int, input().split())
tim = 60 * h + m
md = 60 * 24
for y in range(60 * 25):
	tw = (tim - x * y) % md
	mm = tw % 60
	hh = (tw - mm) / 60
	if '7' in str(hh) or '7' in str(mm):
		print(y)
		exit(0)


def lucky(h, m):
	a = str(h)
	b = str(m)
	if '7' in a or '7' in b:
		return 1
	else:
		return 0
x = int(input())
(h, m) = input().strip().split(' ')
(h, m) = [int(h), int(m)]
cnt = 0
while not lucky(h, m):
	m -= x
	cnt += 1
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
print(cnt)


def check(hh, mm):
	s = str(hh) + str(mm)
	return '7' in s
x = int(input())
(hh, mm) = list(map(int, input().strip().split()))
count = 0
while not check(hh, mm):
	mm -= x
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24
	count += 1
print(count)


x = int(input())
(hh, mm) = map(int, input().split())
ans = 0
while '7' not in str(hh) and '7' not in str(mm):
	mm -= x
	if mm < 0:
		hh = (hh + 23) % 24
		mm += 60
	ans += 1
print(ans)


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


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


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

def checkTime(mins):
	hours = mins // 60
	minutes = mins % 60
	return hours % 10 == 7 or minutes % 10 == 7

def prevMoment(mins):
	if mins - x < 0:
		return 1440 - abs(mins - x)
	else:
		return mins - x
summ = hh * 60 + mm
cnt = 0
while True:
	if checkTime(summ):
		break
	summ = prevMoment(summ)
	cnt += 1
print(cnt)


x = int(input())
(h, m) = tuple(map(int, input().split()))
count = 0
while 1:
	if '7' in str(m) or '7' in str(h):
		print(count)
		break
	m = m - x
	count += 1
	if m < 0:
		m = 60 - (0 - m)
		h -= 1
	if h < 0:
		h = 23


n = int(input())
(hh, mm) = map(int, input().split())
cont = 0
while True:
	if mm % 10 == 7 or hh % 10 == 7:
		print(cont)
		break
	mm -= n
	if mm < 0:
		mm = 60 + mm
		hh -= 1
	if hh < 0:
		hh = 24 + hh
	cont += 1


def f(h, m):
	return True if '7' in str(h) + str(m) else False
x = int(input())
(h, m) = map(int, input().split())
c = 0
while not f(h, m):
	c += 1
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
print(c)


x = int(input())
a = [i for i in range(60)]
(h, m) = map(int, input().split())
str_h = str(h)
str_m = str(m)
ans = 0
while '7' not in str_h and '7' not in str_m:
	m -= x
	if m < 0:
		m = a[m]
		h -= 1
	str_m = str(m)
	str_h = str(h)
	ans += 1
print(ans)


n = int(input().strip())
(h, m) = map(int, input().split())
count = 0
while '7' not in str(h) + str(m):
	m -= n
	if m < 0:
		h -= 1
		m += 60
	count += 1
print(count)


def rs():
	return input().strip()

def ri():
	return int(input())

def ria():
	return list(map(int, input().split()))

def ia_to_s(a):
	return ' '.join([str(s) for s in a])

def solve(x, h, m):
	cnt = 0
	while True:
		if '7' in str(h) + str(m):
			break
		if x <= m:
			m -= x
		else:
			m = m - x + 60
			h -= 1
			if h == -1:
				h = 23
		cnt += 1
	return cnt

def main():
	x = ri()
	(h, m) = ria()
	print(solve(x, h, m))
main()


n = int(input())
l = list(map(int, input().split(' ')))
c = 0
while l[1] % 10 != 7 and l[0] % 10 != 7:
	l[1] = l[1] - n
	if l[1] < 0:
		l[0] = l[0] - 1
		l[1] = l[1] + 60
	if l[0] < 0:
		l[0] = 23
	c = c + 1
print(c)


x = int(input())
(h, m) = map(int, input().split(' '))
c = 0
while h % 10 != 7 and m % 10 != 7:
	c += 1
	m -= x
	if m < 0:
		h -= 1
		m = 60 + m
	if h < 0:
		h = 23
print(c)


def check(h, m):
	while h:
		if h % 10 == 7:
			return True
		h /= 10
	while m:
		if m % 10 == 7:
			return True
		m /= 10
	return False

def main():
	x = int(input())
	(h, m) = map(int, input().split())
	ans = 0
	while True:
		if check(h, m):
			print(ans)
			break
		ans += 1
		m -= x
		if m < 0:
			h -= 1
			m += 60
			if h < 0:
				h = 23
main()


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 f(l, x):
	tx = l[0] * 60 + l[1]
	c = 0
	while True:
		if tx % 60 % 10 == 7 or tx // 60 % 10 == 7:
			return c
		tx -= x
		c += 1
		if tx < 0:
			tx += 1440
x = int(input())
l = list(map(int, input().split()))
print(f(l, x))


def counting(hour, minu, inc):
	count = 0
	h = hour
	m = minu
	x = inc
	flag = 1
	while flag:
		if '7' in str(m) or '7' in str(h):
			print(count)
			flag = 0
		elif m - x < 0:
			temp = m - x
			tem = 60 + temp
			m = tem
			if h - 1 < 0:
				h = 23
			else:
				h -= 1
			count += 1
		else:
			m -= x
			count += 1
x = int(input().strip())
(h, m) = [int(t) for t in input().strip().split(' ')]
counting(h, m, x)


x = int(input())
(hh, mm) = input().split()
if '7' in hh or '7' in mm:
	print(0)
	exit(0)
else:
	if hh[0] == '0':
		hh = int(hh[1])
	else:
		hh = int(hh)
	if mm[0] == '0':
		mm = int(mm[1])
	else:
		mm = int(mm)
	y = 0
	while True:
		y += 1
		if mm - x < 0:
			mm = 60 - (x - mm)
			if hh == 0:
				hh = 23
			else:
				hh -= 1
		else:
			mm -= x
		if '7' in str(hh) or '7' in str(mm):
			print(y)
			exit(0)


def main():
	X = int(input())
	(HH, MM) = map(int, input().split())
	m = MM
	h = HH
	snooze = 0
	while 1:
		if m % 10 == 7 or h % 10 == 7:
			break
		m -= X
		if m < 0:
			m += 60
			h -= 1
		if h < 0:
			h += 24
		snooze += 1
	print(snooze)
main()


time = int(input())
(hr, mi) = map(int, input().split())
count = 0
if hr == 7 or hr == 17:
	print(0)
else:
	while mi % 10 != 7:
		mi -= time
		count += 1
		if mi < 0:
			mi += 60
			hr -= 1
			if hr < 0:
				hr += 24
			if hr == 7 or hr == 17:
				break
	print(count)


x = int(input())
(hh, mm) = map(int, input().split())
ans = 0
while hh % 10 != 7 and mm % 10 != 7:
	ans += 1
	mm -= x
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24
print(ans)


def lucky(x):
	return x % 10 == 7
x = int(input())
(h, m) = 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)


n = int(input())
(a, b) = input().split(' ')
a = int(a)
b = int(b)
ans = 0
while 1:
	if str(a).count('7') > 0 or str(b).count('7') > 0:
		print(ans)
		break
	else:
		if b - n >= 0:
			b = b - n
		else:
			a -= 1
			b += 60
			b -= n
		ans += 1


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())
(n, m) = list(map(int, input().split()))
s = 0
while n % 10 != 7 and n / 10 != 7 and (m % 10 != 7) and (m / 10 != 7):
	m -= x
	s += 1
	if m < 0:
		m = 60 + m
		n = n - 1
		if n < 0:
			n = 23
print(s)


from sys import stdin, stdout

def check_seven(h, m):
	return h // 10 == 7 or m // 10 == 7 or h % 10 == 7 or (m % 10 == 7)

def change(h, m, x):
	if m >= x:
		m -= x
	else:
		m = 60 - x + m
		if h == 0:
			h = 23
		else:
			h -= 1
	return (h, m)
x = int(stdin.readline())
(h, m) = map(int, stdin.readline().strip().split())
count = 0
while not check_seven(h, m):
	(h, m) = change(h, m, x)
	count += 1
print(count)


minn = int(input())
alarm = input()
alarm = alarm.split(' ')
s = int(alarm[0]) * 60 + int(alarm[1])
if s == 0:
	s = 24 * 60
i = 0
n = -1
while i > n:
	if s % 60 % 10 == 7 or s // 60 == 7 or s // 60 % 10 == 7:
		print(i)
		i = n
	else:
		s = s - minn
		i = i + 1
	if s < 0:
		s = s + 1440


x = int(input())
(hh, mm) = map(int, input().split())
m = 60 * 24 * 3 + mm + hh * 60
c = 0
while '7' not in '{}{}'.format(m // 60 % 24, m % 60):
	c += 1
	m -= x
print(c)


import datetime
n = int(input())
(a, b) = input().split()
x = datetime.timedelta(hours=int(a), minutes=int(b))
c = 0
while '7' not in str(x):
	x -= datetime.timedelta(hours=0, minutes=n)
	c += 1
print(c)


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

def time(hh, mm):
	if 0 > mm or mm > 59:
		if mm < 0:
			hh = hh - 1
			mm += 60
		if mm > 59:
			hh += mm // 60
			mm = mm % 60
	if hh > 23 or hh < 0:
		if hh < 0:
			hh += 24
		if hh > 23:
			hh = hh % 24
	return (hh, mm)

def func(hh, mm, n):
	i = 0
	while i >= 0:
		(hh, mm) = time(hh, mm)
		for j in str(hh):
			if j == '7':
				return i
		for k in str(mm):
			if k == '7':
				return i
		i += 1
		mm = mm - n
print(func(hh, mm, n))


b_inp = int(input())
hm_inp = input()
count = 0
hm = list(map(int, hm_inp.split()))

def reverseTime(time, shift):
	time[1] = time[1] - shift
	if time[1] < 0:
		time[0] = time[0] - 1
	time[0] = time[0] % 24
	time[1] = time[1] % 60
	return time
while hm[1] % 10 != 7 and hm[0] % 10 != 7:
	count += 1
	hm = reverseTime(hm, b_inp)
print(count)


def check(hh, mm):
	if hh / 10 == 7 or hh % 10 == 7 or mm % 10 == 7 or (mm / 10 == 7):
		return 1
	return 0
idem = 0
x = int(input())
A = list(map(int, input().split()))
hh = A[0]
mm = A[1]
while 1:
	if check(hh, mm) == 1:
		print(idem)
		exit(0)
	mm -= x
	idem += 1
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh = 23


import sys
n = int(input())
(h, m) = map(int, input().split())
ans = 0
while 1:
	if h % 10 == 7 or m % 10 == 7:
		print(ans)
		sys.exit()
	ans += 1
	m -= n
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h = 23


x = int(input())
desired_str = input()
presses = 0
desired = [int(i) for i in desired_str.split()]
while True:
	if desired_str.find('7') >= 0:
		break
	else:
		desired[1] -= x
		if desired[1] < 0:
			desired[0] -= 1
			desired[1] += 60
		presses += 1
		desired_str = ' '.join([str(i) for i in desired])
print(presses)


x = int(input())
(h, m) = map(int, input().split())
(M, c) = (60 * h + m, 0)
while '7' not in str(M // 60) + str(M % 60):
	c += 1
	M -= x
	if M < 0:
		M += 1440
print(c)


x = int(input())
(h, m) = [int(i) for i in input().split()]
ans = 0
while not ('7' in str(h) or '7' in str(m)):
	tm = (m + h * 60 - x + 24 * 60) % (24 * 60)
	h = tm // 60
	m = tm % 60
	ans += 1
print(ans)


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(ans)


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

def lucky(a):
	return a % 10 == 7 or a // 10 % 10 == 7
ans = 0
while not lucky(hh) and (not lucky(mm)):
	mm -= x
	ans += 1
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24
print(ans)


x = int(input())
(h, m) = map(int, input().split())
ans = 0
while '7' not in str(h) and '7' not in str(m):
	ans += 1
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
print(ans)


x = int(input())
(hh, mm) = map(int, input().split())
if str(hh).count('7') > 0 or str(mm).count('7') > 0:
	print(0)
else:
	count = 0
	while str(hh).count('7') == 0 and str(mm).count('7') == 0:
		mm -= x
		count += 1
		if mm < 0:
			mm = mm + 60
			hh -= 1
			if hh < 0:
				hh = hh + 24
	print(count)


x = int(input())
arr = list(map(int, input().split()))
if arr[0] == 7 or arr[0] == 17 or arr[1] == 7 or (arr[1] == 17) or (arr[1] == 27) or (arr[1] == 37) or (arr[1] == 47) or (arr[1] == 57):
	print(0)
else:
	cout = 0
	while True:
		arr[1] -= x
		if arr[1] < 0:
			arr[1] += 60
			arr[0] -= 1
		if arr[0] < 0:
			arr[0] += 24
		cout += 1
		if arr[1] == 7 or arr[1] == 17 or arr[1] == 27 or (arr[1] == 37) or (arr[1] == 47) or (arr[1] == 57):
			break
		if arr[0] == 7 or arr[0] == 17:
			break
	print(cout)


n = int(input())
p = list(input())
lo = 0
if '7' in p:
	print('0')
else:
	tam = ''.join(p[-2:])
	gf = int(tam)
	gf -= n
	lo += 1
	kam = ''.join(p[0:2])
	for x in range(5555):
		if gf >= 0 and '7' not in str(gf) and ('7' not in kam):
			gf -= n
			lo += 1
		elif gf < 0:
			gf = 60 + gf
			if kam == '00':
				kam = '23'
			elif kam == '01':
				kam = '00'
			else:
				kam = str(int(kam) - 1)
		elif gf > 0 and '7' in str(gf) or '7' in kam:
			break
	print(lo)


import sys
n = int(input())
(h, m) = input().split()

def seven(s):
	return '7' in s
if seven(h + m):
	print(0)
	sys.exit(0)
else:
	ans = 0
	hh = int(h)
	mm = int(m)
	while 1:
		if mm - n >= 0:
			mm = mm - n
		else:
			mm = (mm - n) % 59 + 1
			if hh - 1 >= 0:
				hh = hh - 1
			else:
				hh = 23
		ans += 1
		if seven(str(hh) + str(mm)):
			print(ans)
			sys.exit(0)


x = int(input())
(h, m) = map(int, input().split())
(c, ttlmin) = (0, h * 60 + m)
while '7' not in str(ttlmin // 60) + str(ttlmin % 60):
	ttlmin -= x
	c = c + 1
	if ttlmin < 0:
		ttlmin += 24 * 60
print(c)


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())
(h, w) = map(str, input().split())
if '7' in h or '7' in w:
	print(0)
else:
	h = int(h)
	w = int(w)
	t = 60 * h + w
	f = 1
	c = 0
	while f == 1:
		t = t - x
		c = c + 1
		if t < 0:
			t = t + 1440
		y = t // 60
		z = t % 60
		y = str(y)
		z = str(z)
		if '7' in y or '7' in z:
			print(c)
			exit(0)


snooze_time = int(input())
(hours, minutes) = map(int, input().split())
n_snooze = 0
while '7' not in str(hours) + str(minutes):
	n_snooze += 1
	minutes -= snooze_time
	if minutes < 0:
		minutes += 60
		hours -= 1
	if hours < 0:
		hours += 24
print(n_snooze)


x = int(input())
(h, m) = map(int, input().split())
n = 0
while '7' not in str(m) and '7' not in str(h):
	m -= x
	if m < 0:
		h -= 1
		m += 60
	if h == -1:
		h = 23
	n += 1
print(n)


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)


from datetime import datetime, date, timedelta, time
x = int(input())
(hh, mm) = [int(i) for i in input().split()]
x = timedelta(minutes=x)
wake_up = datetime.combine(date.today(), time(hour=hh, minute=mm))
count = 0
while '7' not in str(wake_up.minute) and '7' not in str(wake_up.hour):
	count += 1
	wake_up -= x
print(count)


x = int(input())
(hh, mm) = map(int, input().split())
t = hh * 60 + mm
k = 0
while True:
	m = t % 60
	h = t // 60
	if m // 10 == 7 or m % 10 == 7 or h // 10 == 7 or (h % 10 == 7):
		break
	k += 1
	t = (t - x + 1440) % 1440
print(k)


def validate(h, m):
	if m < 0:
		m = 60 + m
		h -= 1
	if h < 0:
		h = 23
	return (h, m)

def luck(h, m, x):
	c = 0
	if '7' not in str(m) and '7' not in str(h):
		while 1:
			m = m - x
			c += 1
			(h, m) = validate(h, m)
			if '7' in str(m) or '7' in str(h):
				break
	return c
x = int(input())
(h, m) = map(int, input().split())
c = luck(h, m, x)
print(c)


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


x = int(input())
(h, m) = input().split()
if '7' in h or '7' in m:
	print(0)
else:
	h = int(h)
	m = int(m)
	c = h * 60 + m
	for i in range(1, 100000):
		c = c - x
		if c <= 0:
			c = 24 * 60 + c
		if '7' in str(c % 60) or '7' in str(c // 60):
			print(i)
			break


x = int(input())
(hh, mm) = map(int, input().split())
snoozes = 0
while 0 <= hh <= 23 and 0 <= mm <= 59:
	if hh % 10 == 7 or mm % 10 == 7:
		break
	minutes = hh * 60 + mm
	minutes -= x
	snoozes += 1
	hh = int(minutes // 60)
	if hh < 0:
		hh += 24
	mm = minutes % 60
	if mm < 0:
		mm += 60
print(snoozes)


x = int(input())
a = input()
if '7' in a:
	print(0)
else:
	k = 0
	(h, m) = map(int, a.split())
	while 1:
		if h % 10 == 7 or m % 10 == 7:
			break
		m -= x
		k += 1
		if m < 0:
			m += 60
			h -= 1
		if h <= 0:
			h += 24
	print(k)


x = int(input())
(h, m) = [int(x) for x in input().split()]
ans = 0
while h % 10 != 7 and m % 10 != 7:
	if m < x:
		h -= 1
		h %= 24
	m -= x
	m %= 60
	ans += 1
print(ans)


x = int(input())
(hh, mm) = input().split()
counter = 0
hh = int(hh)
mm = int(mm)
while True:
	if mm > 59:
		mm = mm - 60
		hh += 1
	elif mm < 0:
		mm = 60 + mm
		hh -= 1
	if hh > 23:
		hh = hh - 24
	elif hh < 0:
		hh = 23
	if '7' in str(hh) or '7' in str(mm):
		print(counter)
		break
	mm -= x
	counter += 1


n = int(input())
(hh, mm) = input().split()
t = int(mm)
ans = 0
h = int(hh)
while True:
	if t % 10 == 7 or h % 10 == 7:
		break
	t = t - n
	ans = ans + 1
	if t < 0:
		t = t + 60
		h = h - 1
	if h <= 0:
		h = 24 + h
print(ans)


inp = lambda : map(int, input().split())
x = int(input())
(h, m) = inp()
time = h * 60 + m
m = 10 ** 10
a = [0] * 4
for i in range(0, 24):
	for j in range(60):
		a[0] = i % 10
		a[1] = i // 10
		a[2] = j % 10
		a[3] = j // 10
		fl = 0
		for k in range(0, 4):
			if a[k] == 7:
				fl = 1
				break
		if fl == 1 and 60 * i + j <= time and ((time - 60 * i - j) % x == 0):
			m = min(m, (time - 60 * i - j) // x)
		if fl == 1 and 60 * i + j > time and ((24 * 60 + time - 60 * i - j) % x == 0):
			m = min(m, (24 * 60 + time - 60 * i - j) // x)
print(m)


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)


def main():
	x = eval(input())
	(h, m) = map(int, input().split(' '))
	time = 0
	while ('7' in str(m) or '7' in str(h)) == False:
		m = m - x
		time += 1
		if m < 0:
			h -= 1
			m = 60 + m
		if h < 0:
			h = 23
	print(time)
main()


def transferToMM(hh, mm):
	minute = hh * 60 + mm
	return minute

def transferToHH(minute):
	if minute < 0:
		minute = 24 * 60 + minute
	hh = minute // 60 % 24
	mm = minute % 60
	return [hh, mm]

def check(hh, mm):
	for i in range(len(str(hh))):
		if str(hh)[i] == '7':
			return True
	for i in range(len(str(mm))):
		if str(mm)[i] == '7':
			return True
	return False
step = int(input())
(hh, mm) = input().split()
hh = int(hh)
mm = int(mm)
answer = 0
while not check(hh, mm):
	Time = transferToHH(transferToMM(hh, mm) - step)
	hh = int(Time[0])
	mm = int(Time[1])
	answer += 1
print(answer)


from sys import stdin, stdout
x = int(stdin.readline())
(h, m) = map(int, stdin.readline().split())
cnt = 0
while '7' not in str(h) and '7' not in str(m):
	if m < x:
		if h == 0:
			h = 23
			m = m + 60 - x
			cnt += 1
		else:
			h -= 1
			m = m + 60 - x
			cnt += 1
	else:
		m -= x
		cnt += 1
stdout.write(str(cnt))


x = int(input())
(h, m) = 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)


n = int(input())
(hh, mm) = [int(i) for i in input().split()]

def is_lucky(hh, mm):
	if hh % 10 == 7 or hh // 10 == 7 or mm % 10 == 7 or (mm // 10 == 7):
		return True
	return False
ans = 0
while not is_lucky(hh, mm):
	mm = mm - n
	if mm < 0:
		hh = hh - 1
		mm = 60 + mm
	if hh < 0:
		hh = 23
	ans += 1
print(ans)


d = int(input())
(X, Y) = map(int, input().split())
x = int(X)
y = int(Y)
ans = 0
while '7' not in str(x * 100 + y):
	ans += 1
	for i in range(d):
		y -= 1
		if y < 0:
			y = 59
			x -= 1
			if x == -1:
				x = 23
print(ans)


ReadIntList = lambda : list(map(int, input().split()))
ReadStrList = lambda : list(map(str, input().split()))
ReadInt = lambda : int(input())
ReadMultipleValues = lambda : map(int, input().split())
ReadMultipleValuesStr = lambda : map(str, input().split())
month = {'Jan': '01', 'feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
x = ReadInt()
(hh, mm) = ReadMultipleValues()
output = 0
while hh % 10 != 7 and mm % 10 != 7:
	output += 1
	mm -= x
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24
print(output)


import datetime
x = int(input())
(hh, mm) = [int(i) for i in input().split()]
time = datetime.time(hh, mm, 0, 0)
count = 0
while '7' not in str(time):
	count += 1
	date = datetime.datetime.combine(datetime.datetime.today(), time) - datetime.timedelta(minutes=x)
	time = date.time()
print(count)


x = int(input())
(h, m) = map(int, input().split())
mm = m + h * 60
cnt = 0
while not ('7' in str(h) or '7' in str(m)):
	h = mm // 60
	m = mm - 60 * (mm // 60)
	if '7' in str(h) or '7' in str(m):
		print(cnt)
		exit(0)
	mm -= x
	cnt += 1
print(cnt)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
MOD = 24 * 60
X = int(input()) % MOD
(H, M) = map(int, input().split())
ans = 0
while ''.join(map(str, [H, M])).find('7') < 0:
	t = (H * 60 + M - X + MOD) % MOD
	H = t // 60
	M = t % 60
	ans += 1
print(ans)


xss = int(input())
(nss, mss) = list(map(int, input().split()))
ass = 0
sdgmsdg = 43 * 54
saodnodsaof = 34245 - 23
sadono = 2 * 2
while nss % 10 != 7 and nss // 10 != 7 and (mss % 10 != 7) and (mss // 10 != 7):
	mss -= xss
	if mss < 0:
		mss += 60
		nss -= 1
		if nss < 0:
			nss += 24
	ass += 1
print(ass)


x = int(input())
(hh, mm) = input().split()
ans = 0
while 1:
	if '7' in hh or '7' in mm:
		print(ans)
		break
	else:
		mm = int(mm) - x
		ans = ans + 1
		if mm < 0:
			mm = 60 + mm
			if mm >= 0 and mm < 10:
				mm = '0' + str(mm)
			mm = str(mm)
			if hh == '00':
				hh = '23'
			elif hh[0] == '0':
				hh = '0' + str(int(hh) - 1)
			elif hh == '10':
				hh = '09'
			else:
				hh = str(int(hh) - 1)
		else:
			if mm >= 0 and mm < 10:
				mm = '0' + str(mm)
			mm = str(mm)


n = int(input())
(x, y) = map(int, input().split())
(i, j) = (x, y)
k = 0
while '7' not in str(i) + str(j):
	j = j - n
	if j < 0:
		i -= 1
		j += 60
	if i < 0:
		i += 24
	k += 1
print(k)


x = int(input())
(h, m) = input().split()
if '7' in h or '7' in m:
	print(0)
else:
	(h, m) = (int(h), int(m))
	c = 0
	while True:
		temp = m - x
		if temp < 0:
			h -= 1
			if h < 0:
				h = 24 + h
			m = 60 + temp
		else:
			m = temp
		c += 1
		if '7' in str(h) or '7' in str(m):
			print(c)
			break


x = int(input())
(hh, mm) = map(int, input().split())
if '7' in str(hh) + str(mm):
	ans = 0
else:
	mins = 0
	while '7' not in str(hh) + str(mm) or mins % x != 0:
		mins += 1
		if mm == 0:
			if hh != 0:
				hh -= 1
				mm = 59
			else:
				hh = 23
				mm = 59
		else:
			mm -= 1
	ans = mins // x
print(ans)


from functools import lru_cache
x = int(input())
(h, m) = tuple(map(int, input().split()))

def contains_7(n):
	if n % 10 == 7:
		return True
	elif n // 10 == 7:
		return True
	return False

def to_min(h, m):
	return h * 60 + m

def to_h_m(mins):
	if mins < 0:
		mins = mins + 60 * 24
	return (mins // 60, mins % 60)

def sol(h, m, x):
	i = 0
	while True:
		if contains_7(h) or contains_7(m):
			return i
		else:
			i += 1
			(h, m) = to_h_m(to_min(h, m) - x)
print(sol(h, m, x))


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())
(hour, minut) = input().split(' ')
hour = int(hour)
minut = int(minut)
sum = 60 * hour + minut
i = 0
while not (sum % 10 == 7 or sum // 60 % 10 == 7):
	sum -= x
	i += 1
	while sum < 0:
		sum += 24 * 60
print(i)


def main():
	x = int(input())
	(h, m) = map(int, input().split())
	h = int(h)
	m = int(m)
	t = 0
	while not checktime(h, m):
		(h, m) = uptime(h, m, x)
		t += 1
	print(t)

def uptime(h, m, x):
	m -= x
	if m < 0:
		if h == 0:
			h = 23
		else:
			h -= 1
		m += 60
	return (h, m)

def checktime(h, m):
	return '7' in str(h) or '7' in str(m)
main()


x = int(input())
(hh, mm) = [int(x) for x in input().split(' ')]
turn = 0
while True:
	if str(hh).count('7') >= 1 or str(mm).count('7') >= 1:
		print(turn)
		break
	else:
		mm -= x
		if mm < 0:
			mm += 60
			hh -= 1
			if hh < 0:
				hh += 24
		turn += 1


x = int(input())
(hh, mm) = map(int, input().split())
a = 0
while hh % 10 != 7 and mm % 10 != 7:
	mm -= x
	if mm < 0:
		mm = 60 + mm
		hh -= 1
		if hh < 0:
			hh = 23
	a += 1
print(a)


x = int(input())
(hh, mm) = map(str, input().split())
y = 0
while not ('7' in str(hh) or '7' in str(mm)):
	mm = str(int(mm) - x)
	if int(mm) < 0:
		mm = str(60 + int(mm))
		hh = str(int(hh) - 1)
	if int(hh) < 0:
		hh = str(24 + int(hh))
	while len(hh) != 2:
		hh = '0' + hh
	while len(mm) != 2:
		mm = '0' + mm
	y += 1
print(y)


t = int(input())
(h, m) = map(int, input().split())
A = list(str(h))
B = list(str(m))
c = 0
while '7' not in B and '7' not in A:
	m = m - t
	c = c + 1
	if m < 0:
		m = 60 + m
		h = h - 1
		if h < 0:
			h = 24 + h
	A = list(str(h))
	B = list(str(m))
print(c)


x = int(input())
l1 = [int(x) for x in input().split()]
i = 0
m0 = l1[1]
h0 = l1[0]
y = 0
(h, m) = (h0, m0)
while h != 17 and h != 7 and (str(m)[-1] != '7'):
	time = h * 60 + m
	y += 1
	time -= x
	if time < 0:
		time = 24 * 60 + time
	h = int(time / 60)
	m = time % 60
print(y)


x = int(input())
l = list(map(int, input().split()))
hr = l[0]
mn = l[1]
count = 0
while '7' not in str(hr) and '7' not in str(mn):
	mn -= x
	if mn < 0:
		diff = abs(mn)
		hr -= 1
		if hr < 0:
			hr = 23
		mn = 60 - diff
	if hr < 0:
		hr = 23
	count += 1
print(count)


x = int(input())
k = input().split()
hh = int(k[0])
mm = int(k[1])
k = 0
while '7' not in str(mm) and '7' not in str(hh):
	if x <= mm:
		mm -= x
	else:
		if hh == 0:
			hh = 23
		else:
			hh -= 1
		mm += 60 - x
	k += 1
print(k)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
x = int(input())
(h, m) = map(int, input().split())
ans = 0
while '7' not in str(h) + str(m) and ans < x * 3600 // math.gcd(x, 3600):
	ans += 1
	m -= x
	if m < 0:
		m += 60
		h -= 1
		if h < 0:
			h += 24
print(ans if ans < x * 3600 // math.gcd(x, 3600) else -1)


x = int(input())
c = 0
(h, m) = map(int, input().split())
from datetime import *
t = datetime(9, 9, 9, h, m)
while '7' not in str(t.time()):
	t -= timedelta(minutes=x)
	c += 1
print(c)


x = int(input())
a = input()
z = int(a[4])
c = 10 + z - 7
if c == 10:
	c = 0
t = 0
mm = a[3:]
hh = a[:2]
while '7' not in mm and '7' not in hh:
	mm1 = int(mm)
	mm1 += -x
	hh1 = int(hh)
	if mm1 < 0:
		h = abs(mm1) // 60
		mm1 += 60
		if abs(mm1) / 60 > 0:
			hh1 -= h + 1
		else:
			hh1 -= h
	if len(str(hh1)) == 1:
		hh1 = '0' + str(hh1)
	if len(str(mm1)) == 1:
		mm1 = '0' + str(mm1)
	mm = str(mm1)
	hh = str(hh1)
	t += 1
print(t)


x = int(input())
(h, m) = map(int, input().split())
t = 0
while True:
	if h % 10 == 7 or m % 10 == 7:
		break
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h = 23
	t += 1
print(t)


n = int(input())
(h, m) = map(int, input().split())
if h % 10 == 7 or m % 10 == 7:
	print(0)
	exit(0)
p = h * 60 + m - n
c = 1
while True:
	if p < 0:
		p += 24 * 60
	(hr, mn) = (p // 60, p % 60)
	if hr % 10 == 7 or mn % 10 == 7:
		break
	else:
		p -= n
		c += 1
print(c)


x = int(input())
(h, m) = map(int, input().strip().split())
result = 0
while True:
	if h % 10 == 7 or m % 10 == 7:
		break
	if m - x < 0:
		if h == 0:
			h = 23
		else:
			h = h - 1
		m = 60 - (x - m)
	else:
		m = m - x
	result = result + 1
print(result)


t = int(input())
s = input()
if '7' in s:
	print(0)
else:
	h = list(map(int, s.split(' ')))
	count = 0
	while '7' not in s:
		if h[1] < t:
			if h[0] != 0:
				h[0] -= 1
			else:
				h[0] = 23
			h[1] = h[1] - t + 60
		else:
			h[1] = h[1] - t
		count += 1
		s = str(h[0]) + ' ' + str(h[1])
	print(count)


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())
l = [int(a) for a in input().split()]
n = 0
b = l[1]
if (l[1] - 7) % 10 == 0 or (l[0] - 7) % 10 == 0:
	print('0')
else:
	t = tuple([a for a in range(420, 480)] + [a for a in range(1020, 1080)])
	a = 60 * l[0] + l[1]
	a0 = a
	while a - x > 0:
		a = a - x
		n += 1
		if (a - 7) % 10 == 0 or t.count(a) != 0:
			break
	if a - x <= 0:
		a = 1440 + a
		while a > a0:
			a = a - x
			n += 1
			if (a - 7) % 10 == 0 or t.count(a) != 0:
				break
	print(n)


x = int(input())
(h, m) = map(int, input().split())
ans = 0
while True:
	s = str(h) + str(m)
	if s.find('7') != -1:
		print(ans)
		exit(0)
	m = m - x
	if m < 0:
		m = m + 60
		h = h - 1
		if h < 0:
			h = 23
	ans = ans + 1


(x, [h, m], r) = (int(input()), list(map(int, input().split(' '))), 0)
while '7' not in ''.join((str(c) for c in [h, m])):
	(m, r) = (m - x, r + 1)
	if m < 0:
		(m, h) = (m + 60, (h + 23) % 24)
print(r)


x = int(input())
s = input().split()
hh = int(s[0])
mm = int(s[1])
res = 0
k = 0
st = True
if '7' in str(hh) or '7' in str(mm):
	k = 0
else:
	while st:
		if mm - x < 0:
			mm = 60 - x + mm
			if hh - 1 == -1:
				hh = 23
			else:
				hh -= 1
		else:
			mm -= x
		k += 1
		if '7' in str(hh) or '7' in str(mm):
			st = False
print(k)


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())
(h, m) = map(int, input().split())
n = 0
f = 0
while True:
	while m >= 0 and f != 1:
		if '7' in str(m) or '7' in str(h):
			print(n)
			f = 1
			break
		if m - x < 0:
			m = 60 + m - x
			if h > 0:
				h -= 1
			else:
				h = 23
		else:
			m -= x
		n += 1
	if f == 1:
		break


def lucky(a, b):
	return '7' in str(a) + str(b)
x = int(input())
t = 0
(h, m) = 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 check(hh, mm):
	if '7' in hh + mm:
		return True
	return False

def push(hh, mm, x):
	if hh == '00':
		hh = 0
	else:
		hh = int(hh.lstrip('0'))
	if mm == '00':
		mm = 0
	else:
		mm = int(mm.lstrip('0'))
	if x > mm:
		hh -= 1
	mm -= x
	hh %= 24
	mm %= 60
	return (str(hh).zfill(2), str(mm).zfill(2))
x = int(input())
(hh, mm) = input().split()
count = 0
while not check(hh, mm):
	(hh, mm) = push(hh, mm, x)
	count += 1
print(count)


import collections
import math
import sys
input = sys.stdin.readline

def printnl(val):
	sys.stdout.write(str(val) + '\n')
x = int(input())
(h, m) = map(int, input().split())
ans = int(1000000000.0)
for i in range(24):
	for j in range(60):
		curr = (h - i) * 60 + (m - j)
		curr += 24 * 60
		curr %= 24 * 60
		if curr % x == 0 and '7' in str(i) + str(j):
			ans = min(ans, curr / x)
print(int(ans))


import math as mt
import sys, string
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	x = I()
	(h, m) = M()
	y = 0
	while True:
		if '7' in str(h) or '7' in str(m):
			break
		if m >= x:
			m -= x
		else:
			h = (24 + h - 1) % 24
			m = (60 + (m - x)) % 60
		y += 1
	print(y)
tc = 1
for _ in range(tc):
	main()


n = int(input())
(h, m) = map(int, input().split())
l = 0
while not '7' in str(h) + str(m):
	if m < n:
		if h == 0:
			h = 23
		else:
			h -= 1
		m += 60 - n
	else:
		m -= n
	l += 1
print(l)


IL = lambda : list(map(int, input().split()))
I = lambda : int(input())
x = I()
(hh, mm) = IL()
moves = 0
while hh % 10 != 7 and mm % 10 != 7:
	moves += 1
	mm -= x
	dm = mm % 60 - mm
	mm = mm % 60
	hh -= dm // 60
	hh = hh % 24
print(moves)


def time(h, m, x):
	t = 0
	if '7' in str(h) or '7' in str(m):
		return 0
	else:
		if m[0] == 0:
			m = int(m[1])
		else:
			m = int(m)
		if h[0] == 0:
			h = int(h[1])
		else:
			h = int(h)
		while '7' not in str(m) and '7' not in str(h):
			if m - x < 0:
				remain = x - m
				m = 60 - remain
				h -= 1
				t += 1
			else:
				m -= x
				t += 1
			if h < 0:
				h = 23
	return t
x = int(input())
(h, m) = input().split()
print(time(h, m, x))


x = int(input())
(hh, mm) = map(int, input().split())
count = 0
while '7' not in str(hh) + str(mm):
	if mm - x < 0:
		mm = 60 + mm - x
		hh -= 1
		if hh < 0:
			hh = 23
	else:
		mm -= x
	count += 1
print(count)


def dst(a, b):
	if a <= b:
		return b - a
	return b - a + 60 * 24
x = int(input())
(h, m) = map(int, input().split())
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)


x = int(input())
(h, m) = map(int, input().split())
if '7' in str(h) + str(m):
	print(0)
else:
	time = h * 60 + m
	count = 0
	loop = 0
	while True:
		if time <= 0 and x < 2:
			time = 1440 - time
			loop += 1
		time -= x
		count += 1
		if '7' in str(time // 60) + str(time % 60):
			break
		elif loop > 2:
			break
	print(count)


def minus(h, m, x):
	if m - x < 0:
		m = 60 + m - x
		if h - 1 < 0:
			h = 23
		else:
			h = h - 1
	else:
		m = m - x
	return [h, m]
count = 0
x = int(input())
p = str(input())
(hh, mm) = p.split()
hh = int(hh)
mm = int(mm)
while '7' not in p:
	(hh, mm) = minus(hh, mm, x)
	p = str(hh) + str(mm)
	count += 1
print(count)


x = int(input())
(n, m) = input().split()
n = int(n)
m = int(m)
count = 0
while True:
	h1 = n % 10
	h2 = n / 10
	m1 = m % 10
	m2 = m / 10
	if h1 == 7 or h2 == 7 or m1 == 7 or (m2 == 7):
		break
	else:
		m = m - x
		if m < 0:
			n = n - 1
		m = m % 60
		n = n % 24
		count += 1
print(count)


def isLucky(num):
	while num > 1:
		if num % 10 == 7:
			return True
		num = num // 10
	return False
x = int(input())
(hh, mm) = map(int, input().split())
if isLucky(hh) or isLucky(mm) is True:
	print(0)
else:
	count = 0
	flag = False
	while flag is False:
		mm = mm - x
		if mm < 0:
			mm = 60 + mm
			hh = hh - 1
			if hh < 0:
				hh = 23
		if isLucky(hh) or isLucky(mm) is True:
			flag = True
		count += 1
	print(count)


def haveseven(a):
	return a % 10 == 7 or int(a / 10) == 7
x = int(input())
(hh, mm) = map(int, input().split())
t = hh * 60 + mm
cnt = 0
while '7' not in str(t // 60) + str(t % 60):
	cnt += 1
	t -= x
	if t < 0:
		t += 24 * 60
print(cnt)


x = int(input())
(hh, mm) = map(int, input().split())
t = 0
while not '7' in str(hh) and (not '7' in str(mm)):
	if mm - x < 0:
		y = x - mm
		mm = 60 - y
		hh -= 1
		if hh < 0:
			hh = 23
	else:
		mm -= x
	t += 1
print(t)


x = int(input())
s = list(input())
for i in s:
	if i == '7':
		print(0)
		exit()
s.remove(' ')
w = int(''.join(s[:2]))
z = int(''.join(s[2:]))
c = 0
while 1:
	z = z - x
	if z < 0:
		z = 60 + z
		w = w - 1
	if w < 0:
		w = 24 + w
	c += 1
	if z % 10 == 7 or w % 10 == 7 or z // 10 == 7 or (w // 10 == 7):
		break
print(c)


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())
(hh, mm) = map(str, input().split())
ans = 0
while mm[0] != '7' and mm[1] != '7' and (hh[0] != '7') and (hh[1] != '7'):
	mm = int(mm) - x
	hh = int(hh)
	ans += 1
	if mm < 0:
		hh -= 1
		mm += 60
	if hh < 0:
		hh = 23
	mm = str(mm)
	hh = str(hh)
	if len(mm) == 1:
		mm = '0' + mm
	if len(hh) == 1:
		hh = '0' + hh
print(ans)


x = int(input())
(h, m) = list(map(str, input().split()))
(h2, m2) = (h, m)
ans = 0
temp = 0
while '7' not in str(h2) and '7' not in str(m2):
	if int(m2) - x < 0:
		temp = int(h2)
		if temp - 1 < 0:
			temp = 23
			h2 = temp
		else:
			temp -= 1
			h2 = temp
		temp = 60 - x + int(m2)
		m2 = temp
	else:
		temp = int(m2)
		temp -= x
		m2 = temp
	ans += 1
print(ans)


x = int(input())
(hh, mm) = map(str, input().split())
flag = 0
count = 0
while flag == 0:
	if '7' in hh or '7' in mm:
		flag = 1
		break
	else:
		mm = str(int(mm) - x)
		if int(mm) < 0:
			mm = str(60 + int(mm))
			hh = str(int(hh) - 1)
			if int(hh) < 0:
				hh = str(23)
		count += 1
print(count)


import math
x = int(input())
(h, m) = [int(i) for i in input().split()]
cnt = 0
while 1:
	if h % 10 == 7 or m % 10 == 7:
		break
	if m - x < 0:
		h = h - math.ceil(abs(m - x) / 60)
		if h < 0:
			h = 24 + h
		m = 60 + (m - x)
	else:
		m = m - x
	cnt += 1
print(cnt)


(x, y) = (int(input()), 0)
(h, m) = map(int, input().split())
m += 60 * h
for y in range(999):
	if '7' in '%d%d' % divmod((m - x * y) % 1440, 60):
		break
print(y)


x = int(input())
(h, m) = map(int, input().split())

def ch(a):
	if '7' in str(a):
		return True
	return False
y = 0

def hh(h):
	if h == 0:
		return 23
	else:
		return h - 1
while True:
	if ch(m) or ch(h):
		break
	if m - x < 0:
		m = m + 60 - x
		h = hh(h)
		y += 1
	else:
		m = m - x
		y += 1
print(y)


x = int(input())
(a, b) = list(map(int, input().split()))
ans = 0
while a % 10 != 7 and b % 10 != 7:
	b = b - x
	if b < 0:
		b = b + 60
		a = a - 1
	if a < 0:
		a = 23
	ans += 1
print(ans)


n = int(input())
(x, y) = map(int, input().split())
c = 0
while '7' not in str(x) and '7' not in str(y):
	c = c + 1
	y = y - n
	if y < 0:
		y += 60
		x -= 1
	if x < 0:
		x = x + 24
print(c)


x = int(input())
[h, m] = [int(x) for x in input().split()]
lowTime = [h, m]
highTime = lowTime[:]
lowNum = 0
highNum = 0
while '7' not in str(highTime[0]) and '7' not in str(highTime[1]) and ('7' not in str(lowTime[0])) and ('7' not in str(lowTime[1])):
	lowTime[1] -= x
	if lowTime[1] < 0:
		lowTime[1] += 60
		lowTime[0] -= 1
	if lowTime[0] < 0:
		lowTime[0] = 23
	lowNum += 1
print(lowNum)


import math
x = int(input())
n = input()
li = []
li = n.split(' ')
h = int(li[0])
m = int(li[1])
count = 0
if h == 7 or h == 17 or m == 7 or (m % 10 == 7):
	print(0)
else:
	while 1:
		m = m - x
		count = count + 1
		if m < 0:
			m = m + 60
			h = h - 1
		if h < 0:
			h = h + 24
		if m == 7 or m % 10 == 7:
			break
		if h == 7 or h == 17:
			break
	print(count)


import sys
x = int(sys.stdin.readline())
(h, m) = sys.stdin.readline().split()
h = int(h)
m = int(m)

def sub(h, m, x):
	if x <= m:
		return (h, m - x)
	elif h >= 1:
		return (h - 1, m + 60 - x)
	else:
		return (23, m + 60 - x)

def is_good(d):
	x = d // 10
	y = d % 10
	if y == 7 or d == 7:
		return True
	else:
		return False
iterations = 0
while not (is_good(h) or is_good(m)):
	iterations += 1
	(h, m) = sub(h, m, x)
print(iterations)


x = int(input())
(hh, mm) = map(int, input().split())
t = hh * 60 + mm

def lucky(x):
	if str(x).find('7') != -1:
		return True
	return False
res = 1000000
for h in range(24):
	for m in range(60):
		if lucky(h) or lucky(m):
			s = h * 60 + m
			d = (t - s + 24 * 60) % (24 * 60)
			if d % x == 0:
				y = d // x
				res = min(res, y)
print(res)


def main():
	x = int(input())
	(h, m) = map(int, input().split())
	seconds = m * 60 + h * 60 * 60
	y = 0
	while 1:
		sec = (seconds - y * x * 60 + 24 * 60 * 60) % (24 * 60 * 60)
		m = sec // 60 % 60
		h = sec // 60 // 60
		if '7' in str(m) or '7' in str(h):
			print(y)
			exit(0)
		y += 1
main()


x = int(input())
(a, b) = map(int, input().split())
c = 0
while '7' not in str(a) and '7' not in str(b):
	b = b - x
	if a < 0:
		a += 24
	if b < 0:
		b += 60
		a -= 1
	c += 1
print(c)


n = int(input())
(h, m) = map(int, input().split())
ans = 24 * 60
for i in range(ans):
	if h % 10 == 7 or m % 10 == 7:
		break
	else:
		m -= n
		if m < 0:
			m += 60
			h -= 1
		if h < 0:
			h += 24
print(i)


x = int(input())
(hh, mm) = [int(i) for i in input().split()]
secs = hh * 60 + mm
if '7' in list(str(hh)) or '7' in list(str(mm)):
	print(0)
else:
	i = 0
	while not ('7' in list(str(hh)) or '7' in list(str(mm))):
		secs = (secs - x) % 1440
		i += 1
		(hh, mm) = (secs // 60, secs % 60)
	print(i)


import math
n = int(input())
(h, m) = map(int, input().split())
ans = 0
while h % 10 != 7 and m % 10 != 7:
	if n > m:
		m = 60 + m - n
		h -= 1
	else:
		m -= n
	if h < 0:
		h = 23
	ans += 1
print(ans)


x = int(input())
a = [7, 17, 27, 37, 47, 57]
(h, m) = map(int, input().split())
if h in a or m in a:
	print(0)
else:
	for i in range(24 * 3600):
		m -= x
		if m < 0:
			m += 60
			h -= 1
			if h < 0:
				h += 24
		if m in a or h in a:
			break
	print(i + 1)


x = int(input())
(hh, mm) = map(int, input().split(' '))
count = 0
while True:
	if '7' in str(hh) or '7' in str(mm):
		print(count)
		exit(0)
	mm -= x
	count += 1
	if mm < 0:
		mm = 60 + mm
		hh -= 1
	if hh < 0:
		hh = 23


x = int(input())
s = input()
if s[0] == '0':
	h = int(s[1])
else:
	h = int(s[0]) * 10 + int(s[1])
if s[3] == '0':
	m = int(s[4])
else:
	m = int(s[3]) * 10 + int(s[4])
k = 0
while h // 10 != 7 and h % 10 != 7 and (m // 10 != 7) and (m % 10 != 7):
	m = m - x
	if m < 0:
		a = m
		m = 60 + a
		h = h - 1
		if h < 0:
			h = 23
	k = k + 1
print(k)


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)


n = int(input())
(hh, mm) = map(int, input().split())
num = 0
while '7' not in str(hh) and '7' not in str(mm):
	mm -= n
	if mm < 0:
		mm += 60
		mm = mm % 60
		hh -= 1
		if hh < 0:
			hh = 23
	num += 1
print(num)


def dec(t):
	if t[1] == 0:
		t[1] = 59
		t[0] -= 1
		if t[0] == -1:
			t[0] = 23
		return t
	t[1] -= 1
	return t
x = int(input())
t = list(map(int, input().split(' ')))
ans = 0
while not (t[0] // 10 == 7 or t[0] % 10 == 7 or t[1] // 10 == 7 or (t[1] % 10 == 7)):
	for _ in range(x):
		t = dec(t)
	ans += 1
print(ans)


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 luck(n):
	hh = n // 60
	mm = n % 60
	if hh % 10 == 7 or mm % 10 == 7:
		return True
	return False
x = int(input())
(hh, mm) = map(int, input().split())
cur = hh * 60 + mm
ans = 0
while luck(cur) == False:
	cur -= x
	if cur < 0:
		cur += 60 * 24
	ans += 1
print(ans)


x = int(input())
(hh, mm) = map(int, input().split())
cnt = 0
t = str(hh) + str(mm)
time = hh * 60 + mm
while '7' not in t:
	time -= x
	hh = time // 60
	mm = time % 60
	t = t = str(hh) + str(mm)
	cnt += 1
print(cnt)


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())
l = list(map(int, input().split()))
if (l[0] - 7) % 10 == 0 or (l[1] - 7) % 10 == 0:
	print(0)
else:
	count = 0
	while True:
		if (l[0] - 7) % 10 == 0 or (l[1] - 7) % 10 == 0:
			break
		elif l[1] < 0 and l[0] > 0:
			l[1] = l[1] + 60
			l[0] -= 1
		elif l[1] < 0 and l[0] == 0:
			l[0] = 23
			l[1] = l[1] + 60
		else:
			l[1] -= x
			count += 1
	print(count)


def main():
	x = int(input())
	(h, m) = map(int, input().split())
	count = 0
	while True:
		if m % 10 == 7:
			return count
		if h in {7, 17}:
			return count
		m -= x
		if m < 0:
			h -= 1
			m += 60
		if h < 0:
			h = 23
		count += 1
print(main())


x = int(input())
(a, b) = [str(s) for s in input().split()]
a = int(a)
b = int(b)
h = str(a)
m = str(b)
i = 0
while '7' not in h and '7' not in m:
	b = b - x
	if b < 0:
		b = 59 + b + 1
		a = a - 1
		if a < 0:
			a = 23
	i += 1
	h = str(a)
	m = str(b)
print(i)


def check(x, y):
	for i in x:
		if i == '7':
			return True
	for i in y:
		if i == '7':
			return True
x = int(input())
n = input().split()
h = int(n[0])
m = int(n[1])
time = h * 60 + m + 1440 * 1000000
res = 0
while True:
	time -= res * x
	if check(str((time % 1440 - time % 60) // 60), str(time % 60)):
		print(res)
		break
	time += res * x
	res += 1


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n = I()
	(a, b) = LI()
	r = 0
	while '7' not in str(a) + str(b):
		r += 1
		b -= n
		if b < 0:
			b += 60
			a -= 1
			if a < 0:
				a += 24
	return r
print(main())


x = int(input())
(h, m) = map(int, input().split())
(t, ans) = (60 * h + m, 0)
while '7' not in str(t // 60) + str(t % 60):
	ans += 1
	t -= x
	if t < 0:
		t += 1440
print(ans)


x = int(input())
(hh, mm) = map(int, input().split())
count = 0
if str(hh).count('7') > 0 or str(mm).count('7') > 0:
	print('0')
else:
	while str(hh).count('7') == 0 and str(mm).count('7') == 0:
		mm_new = mm - x
		if mm_new < 0:
			mm = 60 - (x - mm)
			hh_new = hh - 1
			if hh_new < 0:
				hh = 23
			else:
				hh = hh_new
		else:
			mm = mm_new
		count += 1
	print(count)


allwMin = int(input())
hhMm = str(input())
sev7 = True
numOfSno = 0
(hh, mm) = map(int, hhMm.split())
while sev7:
	(hh, mm) = map(int, hhMm.split())
	if hhMm.find('7') == -1:
		numOfSno += 1
		mm -= allwMin
		if mm < 0:
			mm = 60 + mm
			hh -= 1
			if hh < 0:
				hh = 24 + hh
	else:
		sev7 = False
	hhMm = str(hh) + ' ' + str(mm)
print(numOfSno)


def check(a, b):
	a = str(a) + str(b)
	for elem in a:
		if elem == '7':
			return True
	return False

def last(x):
	global h, m
	time = h * 60 + m
	time -= x
	time %= 1440
	m = time % 60
	h = time // 60
x = int(input())
cnt = 0
(h, m) = map(int, input().split())
while not check(h, m):
	last(x)
	cnt += 1
print(cnt)


from math import sqrt
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prog_name():
	x = int(input())
	(h, m) = map(int, input().split())
	if '7' in str(h) or '7' in str(m):
		print(0)
	else:
		cnt = 0
		flag = False
		while flag == False:
			cnt += 1
			if m - x >= 0:
				m -= x
			else:
				h -= 1
				m = 60 + m - x
			if '7' in str(m) or '7' in str(h):
				flag = True
		print(cnt)

def main():
	t = 1
	for unique in range(t):
		prog_name()
main()


x = int(input())
(h, m) = map(str, input().split())
if '7' in h or '7' in m:
	print(0)
else:
	count = 0
	while '7' not in h and '7' not in m:
		if x <= int(m):
			m = int(m) - x
		else:
			m = 60 + int(m) - x
			if int(h) != 0:
				h = int(h) - 1
			else:
				h = 23
		h = str(h)
		m = str(m)
		count = count + 1
	print(count)


x = int(input())
(h, m) = map(int, input().split())
xh = x // 60
x = x % 60

def lucky(h, m):
	return h % 10 == 7 or m % 10 == 7
(hh, mm) = (h, m)
cnt = 0
while True:
	if lucky(hh, mm):
		print(cnt)
		break
	hh -= xh
	mm -= x
	if mm < 0:
		hh -= 1
		mm = (mm + 60) % 60
	while hh < 0:
		hh += 24
	cnt += 1


def CheckIfLucky(num):
	while num >= 1:
		if num % 10 == 7:
			return True
		num = num / 10
	return False
snoozeTime = int(input())
wakingUpTime = input()
wakingH = int(wakingUpTime[:2])
wakingM = int(wakingUpTime[3:5])
numofSnoozes = 0
while True:
	if CheckIfLucky(wakingH) or CheckIfLucky(wakingM):
		print(numofSnoozes)
		break
	if wakingM < snoozeTime:
		wakingM = 60 + wakingM - snoozeTime
		wakingH -= 1
		if wakingH < 0:
			wakingH = 23
	else:
		wakingM -= snoozeTime
	numofSnoozes += 1


n = int(input())
(h, m) = list(map(int, input().split()))
count = 0
while True:
	if h % 10 == 7 or h // 10 == 7 or m % 10 == 7 or (m // 10 == 7):
		break
	m = m - n
	count = count + 1
	if m < 0:
		h = h - 1
		m = m + 60
	if h < 0:
		h = h + 24
print(count)


x = int(input())
(hh, mm) = [int(x) for x in input().split()]
y = 0
while '7' not in str(hh) and '7' not in str(mm):
	mm -= x
	y += 1
	if mm < 0:
		mm += 60
		hh -= 1
	if hh < 0:
		hh += 24
print(y)


x = int(input())
b = [str(i) for i in input().split()]
hh = b[0]
mm = b[1]
if hh[0] == '0':
	hh = hh[1:]
	hh = int(hh)
if mm[0] == '0':
	mm = mm[1:]
	mm = int(mm)
nh = hh
nm = mm
f = 0
y = 0
cnt = 0
need = 60 / x
while f == 0:
	nh = str(nh)
	nm = str(nm)
	if '7' in nh or '7' in nm:
		f = 1
		break
	nh = int(nh)
	nm = int(nm)
	if x > nm:
		d = x - nm
		if nh == 0:
			nh = 23
		else:
			nh -= 1
		nm = 60 - d
	else:
		nm -= x
	y += 1
if f == 1:
	print(y)


x = int(input())
(h, m) = map(int, input().split())
time = h * 60 + m
y = 0
while 7 not in (h // 10, h % 10, m // 10, m % 10):
	time -= x
	y += 1
	if time < 0:
		time += 1440
	(h, m) = (time // 60, time % 60)
print(y)


x = int(input())
(hh, mm) = map(int, input().split())
a = mm
c = 0
if '7' in str(mm):
	m = 0
else:
	while str(hh).count('7') == 0 and str(mm).count('7') == 0:
		mm = mm - x
		c = c + 1
		if mm < 0:
			mm = mm + 60
			hh = int(hh) - 1
			if hh < 0:
				hh = hh + 24
	m = c
print(m)


class AlarmTime:

	def __init__(self, h, m, interval):
		self.h = h
		self.m = m
		self.i = interval

	def is_lucky(self):
		return self.h % 10 == 7 or self.m % 10 == 7

	def un_click(self):
		self.m -= self.i
		if self.m < 0:
			self.m += 60
			self.h -= 1
			if self.h < 0:
				self.h += 24
x = int(input())
data = list(map(int, input().split()))
alarm_time = AlarmTime(data[0], data[1], x)
times = 0
while not alarm_time.is_lucky():
	times += 1
	alarm_time.un_click()
print(times)


x = int(input())
h = list(map(int, input().split()))
j = 0
g = 0
while j == 0:
	if h[1] % 10 == 7 or (h[1] - h[1] % 10) % 100 == 7 or h[0] % 10 == 7 or ((h[0] - h[0] % 10) % 100 == 7):
		j = j + 1
	else:
		h[1] -= x
		g += 1
		if h[1] < 0:
			h[1] = 60 + h[1]
			h[0] -= 1
		if h[0] < 0:
			h[0] = 23
print(g)


n = int(input())
(h, m) = [int(z) for z in input().split()]
if '7' in str(h) or '7' in str(m):
	print(0)
	exit(0)

def time(x):
	t = x // 60
	m = x % 60
	return (t, m)
cur = h * 60 + m
cnt = 0
while True:
	cur -= n
	cnt += 1
	if cur < 0:
		cur += 24 * 60
	(a, b) = time(cur)
	if '7' in str(a) or '7' in str(b):
		print(cnt)
		exit(0)


gap = int(input())
x = input().split()
hh = int(x[0])
mm = int(x[1])
ans = 0
time = hh * 60 + mm

def rep(time):
	return f'{time // 60}{time % 60}'
while '7' not in rep(time):
	if time >= gap:
		time -= gap
	else:
		time = 24 * 60 - (gap - time)
	ans += 1
print(ans)


class Time:

	def __init__(self, h, m):
		self.h = h
		self.m = m

	def decr(self, x):
		for _ in range(x):
			if self.m > 0:
				self.m -= 1
			elif self.h > 0:
				self.h -= 1
				self.m = 59
			else:
				self.h = 23
				self.m = 59

	def is_lucky(self):
		return self.h % 10 == 7 or self.m % 10 == 7
x = int(input())
(h, m) = map(int, input().split())
t = Time(h, m)
out = 0
while not t.is_lucky():
	t.decr(x)
	out += 1
print(out)


import math
x = int(input())
s = input().split()
hh = int(s[0])
mm = int(s[1])
cnt = 0
while True:
	fm = mm % 10
	sm = math.trunc(mm / 10)
	fh = hh % 10
	sh = math.trunc(hh / 10)
	if fm == 7 or sm == 7 or fh == 7 or (sh == 7):
		break
	mm = mm - x
	if mm < 0:
		mm = mm + 60
		hh = hh - 1
		if hh < 0:
			hh = 23
	cnt = cnt + 1
print(cnt)


def decrease(h, m, x):
	if m >= x:
		m -= x
	else:
		m = 60 - (x - m)
		if h == 0:
			h = 23
		elif h <= 1:
			h = 24 - (h - 1)
		else:
			h -= 1
	return [h, m]

def solve(h, m, x):
	count = 0
	v = [7, 17, 27, 37, 47, 57]
	while True:
		if h in v or m in v:
			return count
		(h, m) = decrease(h, m, x)
		count += 1

def main():
	x = int(input())
	arr = list(map(int, input().split(' ')))
	print(solve(*arr, x))
main()


x = int(input())
(hh, mm) = map(int, input().split())
count = 0
while not ('7' in str(hh) or '7' in str(mm)):
	mm -= x
	count += 1
	if mm < 0:
		mm = 60 + mm
		if hh <= 0:
			hh = 24
		hh -= 1
print(count)


x = int(input())
(hh, mm) = input().split()
count = 0
while True:
	if hh.count('7') > 0 or mm.count('7') > 0:
		print(count)
		quit()
	else:
		mm = int(mm)
		mm = mm - x
		if mm < 0:
			mm = mm + 60
			hh = int(hh)
			hh = hh - 1
			if hh < 0:
				hh = hh + 24
			mm = str(mm)
			hh = str(hh)
		else:
			mm = str(mm)
		count = count + 1


x = int(input())
t = input()
ans = 0

def sub(t):
	ti = list(map(int, t.split(' ')))
	ti[1] -= x
	if ti[1] < 0:
		ti[0] -= 1
		ti[1] = 60 + ti[1]
		if ti[0] < 0:
			ti[0] = 24 + ti[0]
	return str(ti[0]) + ' ' + str(ti[1])
while '7' not in t:
	t = sub(t)
	ans += 1
print(ans)
exit()


import sys
import math

def main():
	x = int(input())
	(hour, minute) = map(int, input().split(' '))
	ans = 0
	while True:
		if '7' in str(hour) or '7' in str(minute):
			print(ans)
			break
		ans += 1
		minute -= x
		if minute < 0:
			minute = 60 + minute
			hour -= 1
			if hour < 0:
				hour = 24 + hour
main()


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


x = int(input())
(h, m) = map(int, input().split())

def az(h, m):
	m = m - x
	d = 0
	if m < 0:
		m = m % 60
		d += 1
	h = h - d
	if h < 0:
		h += 24
	return (h, m)
ans = 0
while '7' not in str(h) and '7' not in str(m):
	(h, m) = az(h, m)
	ans += 1
print(ans)


x = int(input())
(h, m) = map(int, input().split())
cnt = 0
while 1:
	if '7' in str(h) or '7' in str(m):
		break
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
	cnt += 1
print(cnt)


n = int(input())
(h, m) = input().split()
h = int(h)
m = int(m)
count = 0
while True:
	if h % 10 == 7 or m % 10 == 7:
		print(count)
		break
	m -= n
	if m < 0:
		m = m + 60
		h -= 1
	if h < 0:
		h = 23
	count += 1


x = int(input())
(hh, mm) = input().split()
s = hh + ' ' + mm
if s.count('7') > 0:
	exit(print(0))
h = int(hh)
m = int(mm)
ans = 0
while True:
	if m - x < 0:
		t = x - m
		m = 60 - t
		if h > 0:
			h -= 1
		else:
			h = 23
	else:
		m -= x
	s = str(h) + str(m)
	ans += 1
	if s.count('7') > 0:
		break
print(ans)


n = int(input())
hh_mm = input().split(' ')
hh = int(hh_mm[0])
mm = int(hh_mm[1])
c = 0
if hh > 23 or mm > 60 or hh < 0 or (mm < 0):
	print('error')
	exit()
while mm % 10 != 7 and hh % 10 != 7:
	mm = mm - n
	if mm < 0:
		hh -= 1
		mm = 60 + mm
	if hh < 0:
		hh = 24 + hh
	c += 1
print(c)


x = int(input())
i = 0
(h, m) = input().split()
h = int(h)
m = int(m)
while (m - 7) % 10 != 0:
	if (h - 7) % 10 == 0:
		break
	m = m - x
	i += 1
	if m < 0:
		h = h - 1
		if h < 0:
			h = 23
		m = 60 + m
print(i)


x = int(input())
(th, tm) = [int(i) for i in input().split()]
ans = False
count = 0
while not ans:
	if '7' in str(th) + str(tm):
		ans = True
		break
	count += 1
	tm -= x
	if tm < 0:
		tm += 60
		th -= 1
print(count)


x = int(input())
(h, m) = map(int, input().split())
ans = 0

def lucky(a, b):
	if a % 10 == 7 or a % 100 == 7 or b % 10 == 7 or (b % 100 == 7):
		return True
	else:
		return False
while not lucky(h, m):
	m -= x
	if m < 0:
		h -= 1
		m += 60
	if h < 0:
		h += 24
	ans = ans + 1
print(ans)


import datetime
x = int(input())
(hh, mm) = map(int, input().split())
ans = 0
d1 = datetime.datetime(1970, 1, 1, hh, mm, 0)
while '7' not in d1.strftime('%H%M'):
	d1 = d1 - datetime.timedelta(minutes=x)
	ans = ans + 1
print(ans)


def check(h, m):
	if h % 10 == 7 or h / 10 == 7:
		return True
	if m % 10 == 7 or m / 10 == 7:
		return True
	return False

def minute(h, m, x):
	if m >= x:
		m -= x
		return (h, m)
	m = m + 60 - x
	h -= 1
	if h < 0:
		h = 23
	return (h, m)
x = int(input())
(h, m) = [int(n) for n in input().split(' ')]
ans = 0
while True:
	if check(h, m):
		break
	ans += 1
	(h, m) = minute(h, m, x)
print(ans)


x = int(input())
(h, m) = map(int, input().split())
y = 0
while not (h % 10 == 7 or m % 10 == 7):
	m -= x
	if m < 0:
		h -= 1
		m = 60 + m
	if h < 0:
		h = 24 + h
	y += 1
print(y)


x = int(input())
import sys
(n, p) = map(int, sys.stdin.readline().split())
if n % 10 == 7 or p % 10 == 7:
	print('0')
else:
	count = 0
	while 1:
		p = p - x
		count += 1
		if p < 0:
			p = p + 60
			n = n - 1
		if n < 0:
			n = n + 24
		if p % 10 == 7 or n % 10 == 7:
			break
	print(count)


(x, y) = (int(input()), 0)
(h, m) = map(int, input().split())
while not '7' in f'{h}{m}':
	y += 1
	(h, m) = divmod((h * 60 + m - x) % 1440, 60)
print(y)


n = int(input())
(h, m) = input().split()
h = int(h)
m = int(m)

def ask(h, m):
	if '7' in str(h):
		return True
	elif '7' in str(m):
		return True
	else:
		return False
count = 0
while ask(h, m) == False:
	m -= n
	count += 1
	if m < 0:
		m = m + 60
		h -= 1
		if h < 0:
			h = h + 24
print(count)


import sys
x = int(sys.stdin.readline().strip())
(h, m) = list(map(lambda y: int(y), sys.stdin.readline().strip().split(' ')))
ans = 0
while '7' not in '{}:{}'.format(h, m):
	m -= x
	ans += 1
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
print(ans)


def judge(hh, mm):
	if hh / 10 == 7 or hh % 10 == 7 or mm % 10 == 7 or (mm / 10 == 7):
		return True
	else:
		return False

def solve(hh, mm, xx):
	hh = (hh - 1) % 24
	mm += 60
	mm -= xx
	if mm >= 60:
		mm -= 60
		hh = (hh + 1) % 24
	return [hh, mm]
x = int(input())
(hh, mm) = input().split()
hh = int(hh)
mm = int(mm)
ans = 0
while True:
	if judge(hh, mm):
		print(ans)
		break
	ans += 1
	(hh, mm) = solve(hh, mm, x)


def htoM(hh, mm):
	M = hh * 60 + mm
	return M

def Mtoh(M):
	M = (M + 1440) % 1440
	mm = M % 60
	hh = M // 60
	return (hh, mm)
x = int(input())
(hh, mm) = map(int, input().split(' '))
M = htoM(hh, mm)
y = 0
while True:
	(temphh, tempmm) = Mtoh(M)
	if tempmm % 10 == 7 or tempmm / 10 == 7 or temphh % 10 == 7 or (temphh / 10 == 7):
		print(y)
		break
	else:
		y += 1
		M -= x


x = int(input())
(h, m) = map(int, input().split())
r = 0
while h != 7 and h != 17 and (m % 10 != 7):
	if m < x:
		h = (h + 23) % 24
	m = (m + 60 - x) % 60
	r += 1
print(r)


import os
import sys
from math import ceil, gcd, sqrt, log2, floor
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	x = int(input())
	(h, m) = map(int, input().split())
	mins = h * 60 + m
	count = 0
	while '7' not in str(h) + str(m):
		m -= x
		if m < 0:
			h -= 1
			m += 60
		count += 1
	print(count)
main()


def isLucky(h, m):
	return '7' in str(h) or '7' in str(m)

def distance(h1, m1, h2, m2):
	return 60 * (h1 - h2) + (m1 - m2)

def addTime(h, m, snooze):
	if m + snooze >= 60:
		m2 = m + snooze - 60
		h2 = h + 1
	else:
		h2 = h
		m2 = m + snooze
	return (h2, m2)

def minusTime(h, m, snooze):
	if h == 0:
		hcopy = 24
		(h2, m2) = minusTime(hcopy, m, snooze)
	elif m - snooze < 0:
		m2 = 60 + (m - snooze)
		h2 = h - 1
	else:
		m2 = m - snooze
		h2 = h
	if h2 >= 24:
		h2 = h2 - 24
	return (h2, m2)

def main():
	snooze = int(input())
	(h, m) = map(lambda x: int(x), input().split(' '))
	click = 0
	while not isLucky(h, m):
		(h, m) = minusTime(h, m, snooze)
		click += 1
	print(click)
main()


x = int(input())
(a, b) = map(int, input().split())
if a == 0 and b == 0:
	a = 24
s = 0
to = a * 60 + b
while 1:
	a = to // 60
	b = to % 60
	if '7' in str(a) or '7' in str(b):
		print(s)
		quit()
	else:
		to -= x
		s += 1


y = int(input())
(h, m) = input().split()
(h, m) = (int(h), int(m))
step = 0
while not ('7' in str(h) or '7' in str(m)):
	m -= y
	step += 1
	if m < 0:
		m = m % 60
		h -= 1
print(step)


from datetime import timedelta
subtract = int(input())
(hour, minute) = map(int, input().split())
time_1 = timedelta(hours=hour, minutes=minute)
time_2 = timedelta(minutes=subtract)
ans = 0
while '7' not in str(time_1):
	time_1 = time_1 - time_2
	ans += 1
print(ans)


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


x = int(input())
(hh, mm) = map(int, input().split())
ans = 0
while True:
	if (str(hh) + str(mm)).count('7') >= 1:
		break
	mm -= x
	if mm < 0:
		mm += 60
		hh -= 1
		if hh < 0:
			hh = 23
	ans += 1
print(ans)


times = int(input())
array = [int(i) for i in input().split()]
x = 0
while not str(array[0]).__contains__('7') and (not str(array[1]).__contains__('7')):
	array[1] = array[1] - times
	if array[1] < 0:
		array[0] = array[0] - 1
		if array[0] < 0:
			array[0] = 23
		array[1] = 60 + array[1]
	x = x + 1
print(x)


x = int(input())
(h, m) = map(int, input().split())

def islucky(h, m):
	h1 = h % 10
	h2 = (h - h1) / 10
	m1 = m % 10
	m2 = (m - m1) / 10
	if h1 == 7 or h2 == 7 or m1 == 7 or (m2 == 7):
		return True
	else:
		return False
count = 0
th = h
tm = m
if islucky(h, m):
	print('0')
else:
	while not islucky(th, tm):
		if tm - x >= 0:
			tm -= x
			count += 1
		else:
			if th - 1 < 0:
				th = 23
			else:
				th -= 1
			tm = 60 + tm - x
			count += 1
	print(count)


def test(h, m):
	return m % 10 == 7 or h % 10 == 7
x = int(input())
(h, m) = list(map(int, input().split()))
count = 0
while not test(h, m):
	m -= x
	if m < 0:
		m += 60
		h = (h - 1) % 24
	count += 1
print(count)


x = int(input())
(h, m) = map(int, input().split())
cnt = 0
while not str(h).__contains__('7') and (not str(m).__contains__('7')):
	if m - x < 0:
		if h == 0:
			h = 23
		else:
			h -= 1
		m = 60 - x + m
	else:
		m -= x
	cnt += 1
print(cnt)


x = int(input())
a = input()
c = 0
e = 0
h = int(a[:2])
m = int(a[3:])
if '7' in a:
	print(0)
else:
	while 1:
		while m >= 0:
			c += 1
			m -= x
			if '7' in str(m) and m > 0:
				print(c)
				e = 10
				break
		if e == 10:
			break
		else:
			m += 60
			if '7' in str(m):
				print(c)
				break
			if h == 0:
				h = 23
			else:
				h -= 1
			if '7' in str(h):
				print(c)
				break


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 sev(k):
	return k // 10 == 7 or k % 10 == 7

def check(k):
	return sev(k // 60) or sev(k % 60)
x = int(input())
a = input()
a = list(a.split(' '))
h = int(a[0])
m = int(a[1])
time = h * 60 + m
happy = time
ans = 0
while check(happy) == False:
	happy -= x
	ans += 1
	if happy < 0:
		happy += 24 * 60
print(ans)


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)


x = int(input())
(h, m) = [int(k) for k in input().split(' ') if k]
y = 0

def lucky(a, b):
	return '7' in str(a) or '7' in str(b)
while not lucky(h, m):
	m -= x
	if m < 0:
		m += 60
		h -= 1
	if h < 0:
		h += 24
	y += 1
print(y)


x = int(input())
s = input()
if s.find('7') != -1:
	print(0)
else:
	s = s.split()
	k = 0
	(h, m) = [int(s[i]) for i in range(len(s))]
	m1 = h * 60 + m
	while str(m1 // 60).find('7') == -1 and str(m1 % 60).find('7') == -1:
		m1 -= x
		k += 1
	print(k)


x = int(input())
(h, m) = map(int, input().split())
dh = 24 * 60
t = lambda h, m: (h * 60 + m) % dh
b = lambda t: (t // 60, t % 60)
ct = t(h, m)

def solve(ct):
	for i in range(dh):
		if str(b(ct)[0]).__contains__('7') or str(b(ct)[1]).__contains__('7'):
			return i
		ct -= x
print(solve(ct))


def lucky(h, m):
	return '7' in str(h) or '7' in str(m)
x = int(input())
(h, m) = [str(i) for i in input().split(' ')]
c = 0
while not lucky(h, m):
	if int(m) < x:
		h = int(h) - 1
		h %= 24
		h = str(h)
		m = int(m)
		m -= int(x)
		m += 60
		m = str(m)
	else:
		m = int(m)
		m -= x
		m = str(m)
	c += 1
print(c)


def test7(h, m):
	if h % 10 == 7:
		return True
	if m % 10 == 7:
		return True
	return False
x = int(input())
(h, m) = map(int, input().split(' '))
n = 0
while True:
	if test7(h, m):
		print(n)
		break
	m -= x
	if m < 0:
		m += 60
		h -= 1
		if h < 0:
			h += 24
	n += 1


x = int(input())
hm = list(map(int, input().split()))
org = 60 * hm[0] + hm[1]
mins = org
days = 0
while '7' not in str(mins % 1440 // 60) and '7' not in str(mins % 1440 - 60 * (mins % 1440 // 60)):
	mins -= x
print(int((org - mins) / x))


def check(h, m):
	if '7' in str(h) or '7' in str(m):
		return True
	return False
x = int(input())
(h, m) = map(int, input().split())
c = 0
while True:
	if not check(h, m):
		m -= x
		c += 1
		if m < 0:
			m = (m + 60) % 60
			h -= 1
		if h < 0:
			h = 23
			m = (m + 60) % 60
	else:
		break
print(c)


n = int(input())
(h, m) = map(int, input().split())
ans = 0
while True:
	if m % 10 == 7 or h % 10 == 7:
		break
	m = m - n
	if m + n >= 0 and m < 0:
		m += 60
		h -= 1
		if h + 1 == 0:
			h = 23
	ans += 1
print(ans)


x = int(input())
l = list(map(int, input().split()))
if l[1] % 10 == 7 or l[0] % 10 == 7:
	print(0)
else:
	b = l[1]
	for i in range(1, 10001):
		if b - x >= 0:
			b = b - x
		else:
			b = b - x + 60
			l[0] = l[0] - 1
			if l[0] < 0:
				l[0] = 23
		if b % 10 == 7 or l[0] % 10 == 7:
			break
	print(i)


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


x = int(input())
(h, m) = map(int, input().split())

def is_lucky(a, b):
	return '7' in str(a) or '7' in str(b)
res = 0
while not is_lucky(h, m):
	res += 1
	m -= x
	if m < 0:
		h -= 1
		if h < 0:
			h += 24
		m += 60
print(res)


(X, N) = (int(input()), 0)
Time = list(map(int, input().split()))
TimeToMinutes = Time[0] * 60 + Time[1]
while True:
	(Hour, Min) = (str(TimeToMinutes // 60), str(TimeToMinutes % 60))
	if '7' in Hour or '7' in Min:
		break
	N += 1
	TimeToMinutes -= X
	if TimeToMinutes < 0:
		TimeToMinutes = 24 * 60 + TimeToMinutes
print(N)


x = int(input())
(h, m) = list(map(int, input().strip().split(' ')))

def clock_time(h, m, x):
	count = 0
	while '7' not in str(h) + str(m):
		m -= x
		count += 1
		if m < 0:
			m += 60
			h -= 1
			if h < 0:
				h = 23
	return count
print(clock_time(h, m, x))


TN = 1

def solution():
	x = int(input())
	(hh, mm) = map(int, input().split())
	c1 = 0
	while True:
		if '7' in str(hh) or '7' in str(mm):
			break
		if mm - x >= 0:
			mm -= x
		else:
			if hh - 1 >= 0:
				hh -= 1
			else:
				hh = 23
			mm = 60 + mm - x
		c1 += 1
	print(c1)
while TN != 0:
	solution()
	TN -= 1


a = int(input())
(ch, m) = map(int, input().split())
o = 0
while (str(ch) + str(m)).find('7') == -1:
	for i in range(a):
		m -= 1
		if m == -1:
			ch -= 1
			m = 59
			if ch == -1:
				ch = 23
	o += 1
print(o)


t = int(input())
(a, b) = [int(x) for x in input().split()]
r = 0
while True:
	str1 = str(a)
	str2 = str(b)
	if '7' in str1 or '7' in str2:
		print(r)
		break
	b = b - t
	if b < 0:
		b = 60 + b
		a = a - 1
		if a < 0:
			a = 23
	r = r + 1


def find(h, m):
	return h // 10 == 7 or h % 10 == 7 or m // 10 == 7 or (m % 10 == 7)
n = int(input())
(h, m) = map(int, input().split())
i = 0
while not find(h, m):
	i += 1
	m -= n
	if m < 0:
		h -= 1
		m = 60 + m
		if h < 0:
			h = 23
print(i)


interval = int(input())
pressed = 0
(h, m) = [int(x) for x in input().split()]
while h not in [7, 17] and (not m % 10 == 7):
	m -= interval
	pressed += 1
	if m < 0:
		m += 60
		h -= 1
		if h < 0:
			h += 24
print(pressed)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(1):
	k = inin()
	(h, m) = cin()
	c = 0
	s = str(h) + ':' + str(m)
	while '7' not in s:
		if k > m:
			if h > 0:
				h -= 1
				m = 60 - (k - m)
			else:
				h = 23
				m = 60 - (k - m)
		else:
			m -= k
		s = str(h) + ':' + str(m)
		c += 1
	print(c)


x = int(input())
(h, m) = map(str, input().split())
if '7' in h or '7' in m:
	print('0')
else:
	t = int(h) * 60 + int(m)
	temp = t - 1
	while 1:
		mm = str(temp % 60)
		hh = str(temp // 60)
		if ('7' in mm or '7' in hh) and (t - temp) % x == 0:
			print((t - temp) // x)
			break
		temp = temp - 1


x = int(input())
t = input()
h = ''
m = ''
s = ''
d = 0
j = 0
for i in t:
	if i == ' ':
		d = 1
		continue
	elif d == 0:
		h = h + i
	else:
		m = m + i
	s = s + i
while True:
	if s.find('7') != -1:
		break
	j = j + 1
	ih = int(h)
	im = int(m)
	if im - x < 0:
		im = 60 + im - x
		if ih - 1 < 0:
			ih = 23
		else:
			ih = ih - 1
	else:
		im = im - x
	s = str(ih) + str(im)
	h = str(ih)
	m = str(im)
print(j)