#include <bits/stdc++.h>
using namespace std;
const string nl = "\n";
const long long MOD = 1000000007;
const long long ARR_MAX = 1e5 + 1;
int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  set<long long> s;
  long long x;
  for (long long i = 0; i < n; i++) cin >> x, s.insert(x);
  for (auto it = s.begin(); it != s.end(); it++) {
    a.push_back(*it);
  }
  n = a.size();
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 2 * a[i]; j < a[n - 1] + a[i]; j += a[i]) {
      long long x = j;
      long long ind = lower_bound(a.begin() + i, a.end(), x) - a.begin();
      ind--;
      ans = max(ans, a[ind] % a[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
