N,K=map(int,input().split()) ans=0 import itertools A=list(map(int,input().split())) list(itertools.permutations(A)) for a in list(itertools.permutations(A)): c=K for i in range(N): c=c%a[i] ans=max(c,ans) print(ans)