n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) ans = 0 for b in range(1, 1<>i) & 1: res %= a[i] ans = max(ans, res%a[n-1]) print(ans)