from random import shuffle from time import time N, K = map(int, input().split()) A = [int(a) for a in input().split()] sTime = time() ma = 0 while time() - sTime < 1.8: shuffle(A) s = K for a in A: s %= a ma = max(ma, s) print(ma)