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