Ответ:
nums = []
for i in range(int(input()):
num = int(input())
if str(num)[-1] == '4':
nums.append(num)
print(min(nums))