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