#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
struct Problem {
  void Solve() {
    UL N;
    cin >> N;
    vector<UL> A(N);
    for (UL i = 0; i < (N); i++) cin >> A[i];
    sort(A.rbegin(), A.rend());
    vector<UL> B(1000001, 10000000);
    for (UL i = 0; i < (N); i++) B[A[i]] = A[i];
    for (UL i = 1000000; i > 0; i--) B[i - 1] = min(B[i], B[i - 1]);
    UL ans = 0;
    for (UL i = 0; i < (N); i++) {
      for (UL j = ans + 2; (ULL)j * j < A[i]; j++) {
        if (B[j] == j) ans = max(ans, A[i] % j);
      }
      for (UL j = 2; (ULL)j * j < A[i]; j++) {
        UL p = A[i] / j + 1;
        if (p <= ans) break;
        if (B[p] < A[i]) ans = max(ans, A[i] % B[p]);
      }
    }
    cout << ans << endl;
  }
  Problem();
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem::Problem() { cout << fixed << setprecision(10); }
