n, k = map(int, input().split()) a = list(map(int, input().split())) print(max(k % num % min(a) for num in a))