#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
bool present[2 * N];
int lessnum[2 * N];
bool mysort(int &a, int &b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, i, x, j, cur;
  cin >> n;
  vector<int> a;
  for (i = 0; i < n; i++) {
    cin >> x;
    present[x] = 1;
    a.push_back(x);
  }
  for (i = 1; i < 2 * N; i++) {
    if (present[i - 1])
      lessnum[i] = i - 1;
    else
      lessnum[i] = lessnum[i - 1];
  }
  int maxi = 2 * lessnum[N - 1];
  int ans = 0;
  sort(a.begin(), a.end(), mysort);
  for (i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) continue;
    for (j = 2 * a[i]; j < maxi; j += a[i]) {
      cur = lessnum[j] % a[i];
      if (cur > ans) ans = cur;
    }
  }
  cout << ans << endl;
  return 0;
}
