Загрузка данных


a = int(input())
m = -0

while a != 0:
    if 99 < a < 1000 and a % 2 != 0 and a % 3 != 0 and a % 10 != 7:
        m = max (a, m)
        
    a = int(input())

print (m)