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