N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) from itertools import groupby, accumulate, product, permutations, combinations ans = 0 for p in product([0,1],repeat=N-1): k = K for i in range(N-1): if p[i]==1: k %= A[i] k%=A[-1] ans = max(ans,k) print(ans)