#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 1;
int n, a, u[N], last, f[N], ans;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    u[a] = 1;
  }
  for (int i = 1; i < N; ++i) {
    last = max(last, u[i] * i);
    f[i] = last;
  }
  for (int i = 1; i < N; ++i) {
    if (!u[i]) continue;
    for (int j = i + i; j < N; j += i) {
      ans = max(ans, f[j - 1] % i);
    }
  }
  cout << ans;
  return 0;
}
