e,s=open("input.txt").readlines();t={b:b-(int(e)%b)for b in (int(x)for x in s.split(',')if x!='x')};n=min(t,key=t.get);print(n*t[n])