#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int upperlimit = 1e6 + 1;
const int mod = 1e9 + 7;
int arr[upperlimit];
int segtree[4 * upperlimit];
int temp[upperlimit];
void build(int node, int i, int j) {
  if (i == j) {
    segtree[node] = i + temp[i];
    return;
  }
  int mid = (i + j) >> 1;
  build(2 * node, i, mid);
  build(2 * node + 1, mid + 1, j);
  segtree[node] = max(segtree[2 * node], segtree[2 * node + 1]);
}
int query(int node, int i, int j, int l, int r) {
  if ((i > r) || (l > j) || (i > j) || (l > r)) return 0;
  if ((i >= l) && (j <= r)) return segtree[node];
  int mid = (i + j) >> 1;
  return max(query(2 * node, i, mid, l, r),
             query(2 * node + 1, mid + 1, j, l, r));
}
int n;
int poss(int k) {
  bool check = false;
  for (int i = 1; i <= n; i++) {
    if (arr[i] <= k) continue;
    if (query(1, 1, upperlimit - 1, 1, arr[i] - k) > arr[i]) {
      check = true;
    }
  }
  return check;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  sort(arr + 1, arr + n + 1);
  for (int i = 1; i <= n; i++) {
    if (arr[i] != arr[i - 1]) {
      for (int j = arr[i]; j < upperlimit; j += arr[i]) temp[j] = arr[i];
    }
  }
  build(1, 1, upperlimit - 1);
  int l = 0, r = upperlimit;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (poss(mid))
      l = mid;
    else
      r = mid;
  }
  printf("%d", l);
  return 0;
}
