N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 for S in range(1<>(N-1))&1: continue now = K for i in range(N): if (S>>i)&1: now %= A[i] ans = max(ans, now) print(ans)