#include <bits/stdc++.h>
using namespace std;
long long m, i, j, x, y, a[2000001];
int main() {
  cin >> m;
  for (i = 0; i < m; i++) cin >> x, a[x] = x;
  for (i = 2; i <= 2000000; i++)
    if (a[i] == 0) a[i] = a[i - 1];
  for (i = 2; i <= 1000000; i++) {
    if (a[i] == i)
      for (j = 2 * i - 1; j <= 2000000; j += i) y = max(y, a[j] % i);
  }
  cout << y;
}
