#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, sum, cnt, ans, a[2000005], f[2000005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    a[x] = x;
  }
  for (int i = 1; i <= 2000000; i++) f[i] = max(a[i], f[i - 1]);
  for (int i = 1; i <= 1000000; i++) {
    if (a[i])
      for (int j = i + i; j <= 2000000; j += i) ans = max(ans, f[j - 1] % i);
  }
  printf("%d\n", ans);
  return 0;
}
