n,k=map(int,input().split())
a=list(map(int,input().split()))
from itertools import permutations
ans=0
for i in permutations(a,n):
  kk=k
  for j in i:kk%=j
  ans=max(ans,kk)
print(ans)