#include <bits/stdc++.h>
using namespace std;
int n, i, a[2000005] = {0};
int main() {
  cin >> n;
  while (n--) {
    cin >> i;
    a[i] = i;
  }
  for (int j = 1; j < 2000005; j++)
    if (a[j] == 0) a[j] = a[j - 1];
  int sol = 0;
  for (int j = 2; j < 2000005; j++)
    if (a[j] == j)
      for (i = j - 1; i < 2000005; i += j)
        if (a[i] % j > sol and a[i] > j) sol = a[i] % j;
  cout << sol << endl;
}
