#include <bits/stdc++.h>
using namespace std;
int a[200009], n, f[2000009];
bool cmp(int x, int y) { return x > y; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n, cmp);
  int num = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) a[num++] = a[i];
  }
  n = num;
  for (int i = 1; i <= 1000000; i++) f[i] = 1e9;
  for (int i = 0; i < n; i++) f[a[i]] = a[i];
  for (int i = 1000000 - 1; i >= 1; i--) f[i] = min(f[i + 1], f[i]);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int lim = 0;
    for (int j = 2; j * j <= a[i]; j++) {
      ans = max(ans, a[i] % f[a[i] / j + 1]);
      lim = a[i] / j;
    }
    for (int j = n - 1; a[j] <= lim && j > i; j--) ans = max(ans, a[i] % a[j]);
  }
  printf("%d\n", ans);
  return 0;
}
