n = int(input('Введите n '))
min = 30001
for i in range(1,n):
a = int(input('Введите a: '))
if (a%10 == 2 or a %10 == 8) and a < min:
min = a
print(min)
n = int(input('Введите n '))
min = 30001
for i in range(1,n):
a = int(input('Введите a: '))
if (a%10 == 2 or a %10 == 8) and a < min:
min = a
print(min)