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