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