#include <bits/stdc++.h>
using namespace std;
long long n, x, a[2000001], maxi, ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    a[x] = x;
    maxi = max(maxi, x);
  }
  for (long long i = 1; i < 2 * maxi; ++i)
    if (!a[i]) a[i] = a[i - 1];
  for (long long i = maxi - 1; i >= 1; --i)
    if (a[i] == i)
      for (long long j = 2 * i - 1; j < 2 * maxi; j += i)
        ans = max(ans, a[j] % i);
  cout << ans;
}
