#include <bits/stdc++.h>
using namespace std;
int fn() { return 1; }
int main() {
  long long n;
  scanf("%lld", &n);
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a.begin(), a.end());
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] == 1 or (a[i] == a[i - 1] and i)) continue;
    for (long long j = a[i] << 1; j <= a[n - 1] + a[i]; j += a[i]) {
      vector<long long>::iterator idx = lower_bound(a.begin(), a.end(), j);
      long long cur = *(idx - 1);
      ans = max(ans, cur % a[i]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
