import numpy as np N, K = map(int, input().split()) A = np.array(list(map(int, input().split()))) rng = np.random.default_rng() ans = 0 for i in range(1000000): rng.shuffle(A) tmp = K for a in A: tmp %= a ans = max(ans, tmp) print(ans)