N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 a = A.pop() from itertools import product for Iter in product(range(2), repeat=N - 1): x = K for i in range(N - 1): if Iter[i]: x %= A[i] x %= a ans = max(x, ans) print(ans)