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