#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void rd(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void pp(T... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
void add(long long &x, long long y) {
  x += y;
  if (x >= 1000000007) x %= 1000000007;
  if (x < 0) x = x % 1000000007 + 1000000007;
}
const int N = 1e6;
bool at[2 * N + 1];
int closest[2 * N + 1];
void solve() {
  int n;
  rd(n);
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  ;
  for (int x : a) at[x] = 1;
  sort(a, a + n);
  closest[1] = -1;
  for (long long i = (long long)(2); i <= (long long)(2 * N); i++) {
    if (at[i - 1])
      closest[i] = i - 1;
    else
      closest[i] = closest[i - 1];
  }
  long long ans = 0;
  for (long long x = (long long)(1); x <= (long long)(N); x++) {
    if (!at[x]) continue;
    for (int j = 2 * x; j <= 2 * N; j += x) {
      if (closest[j] != -1) {
        ans = max(ans, 1LL * (closest[j] % x));
      }
    }
  }
  cout << ans << "\n";
}
void prep() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(12);
  prep();
  int t = 1;
  while (t--) solve();
  return 0;
}
