#include <bits/stdc++.h>
using namespace std;
const int maxa = 1000005;
bool a[2 * maxa];
int pre[2 * maxa];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    a[k] = true;
  }
  pre[0] = 0;
  for (int i = 1; i < 2 * maxa; ++i) {
    if (a[i - 1])
      pre[i] = i - 1;
    else
      pre[i] = pre[i - 1];
  }
  int maxm = 0;
  for (int i = 1; i < maxa; ++i) {
    if (!a[i]) continue;
    for (int j = 2 * i; j < 2 * maxa; j += i) {
      maxm = max(maxm, pre[j] % i);
    }
  }
  cout << maxm << endl;
}
