#include <bits/stdc++.h>
using namespace std;
struct pair_hash {
  template <typename T1, typename T2>
  size_t operator()(const pair<T1, T2> &p) const {
    auto h1 = hash<T1>{}(p.first);
    auto h2 = hash<T2>{}(p.second);
    return h1 ^ h2;
  }
};
const long long INFLL = 2 * (long long)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
void die() {
  cout << "-1";
  exit(0);
}
const int NMAX = 2 * 1e6 + 5;
const int MOD = 1e9 + 7;
const double PI = atan(1) * 4;
const double EPS = 1e-12;
int n;
int prv[NMAX], a[NMAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    a[temp] = 1;
  }
  for (int i = 2; i < NMAX; i++)
    if (a[i - 1])
      prv[i] = i - 1;
    else
      prv[i] = prv[i - 1];
  int ans = 0;
  for (int i = 1; i <= (int)1e6; i++) {
    if (!a[i]) continue;
    for (int k = 2; i * k <= (int)2 * 1e6; k++) ans = max(ans, prv[i * k] % i);
  }
  cout << ans;
  return 0;
}
