#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x;
  int mxnum = 0;
  vector<int> vis(1000000, 0);
  vector<int> num(1000000, 0);
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (mxnum < x) mxnum = x;
    vis[x] = 1;
  }
  for (int i = 1; i <= mxnum; i++) {
    if (vis[i])
      num[i] = i;
    else
      num[i] = num[i - 1];
  }
  int ans = 0;
  for (int aj = 1; aj <= mxnum; aj++) {
    if (!vis[aj]) continue;
    if (ans < mxnum % aj) ans = mxnum % aj;
    for (int p = aj * 2; p <= mxnum; p += aj) {
      if (ans < num[p - 1] % aj) ans = num[p - 1] % aj;
    }
  }
  cout << ans;
  return 0;
}
