from itertools import product N, K = map(int, input().split()) A = list(map(int, input().split())) result = 0 for p in product([True, False], repeat=2): t = K for i in range(N): if p[i]: t %= A[i] result = max(result, t) print(result)