import itertools N,K = map(int, input().split()) A = [int(a) for a in input().split()] s = min(A) ans = 0 for i in range(1, N+1): num = K for C in itertools.combinations(A, i): C = list(C) C.sort(reverse=True) for c in C: num %= c ans = max(ans, num%s) print(ans)