#include <bits/stdc++.h>
using namespace std;
const int mx = 2e6 + 5;
int main() {
  int n, x, ret = 0;
  cin >> n;
  vector<int> a(mx, 0), b(mx, 0);
  for (int i = 0; i < n; i++) cin >> x, a[x] = x;
  for (int i = 1; i < mx; i++) b[i] = max(b[i - 1], a[i]);
  for (int i = 1; i < mx; i++)
    if (a[i])
      for (int j = 2; j * i < mx; j++) ret = max(ret, b[j * i - 1] % i);
  cout << ret << endl;
  return 0;
}
