#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
int inp() {
  int s = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s;
}
int ar[N];
int dd[N];
int n, mx, rs, x;
int main() {
  n = inp();
  for (int i = 1; i <= n; i++) {
    x = inp();
    ar[x] = x;
    mx = max(mx, ar[x]);
  }
  for (int i = 1; i <= 2 * mx; i++)
    if (ar[i] == 0) ar[i] = ar[i - 1];
  for (int i = 1; i <= 2 * mx; i++) {
    if (ar[i] != i) continue;
    for (int j = 2 * i - 1; j <= 2 * mx; j += i) rs = max(rs, ar[j] % i);
  }
  cout << rs << endl;
  return 0;
}
