#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
template <typename T>
inline T sq(T x) {
  return x * x;
}
template <typename T>
inline T In() {
  T x;
  cin >> x;
  return x;
}
template <typename T>
inline void Out(T& x) {
  cout << x;
}
template <typename T>
inline void sort(T& v) {
  sort(begin(v), end(v));
}
template <typename T>
inline void revs(T& v) {
  reverse(begin(v), end(v));
}
template <typename T>
inline void uniq(T& v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
template <typename T>
inline int ubnd(T& v, typename T::value_type& x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
template <typename T>
inline int lbnd(T& v, typename T::value_type& x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
template <typename T, typename F>
inline void inpt(T& v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
template <typename T, typename F>
inline void show(T& v, F f, string d = " ", string e = "\n") {
  int i = 0;
  for (auto& x : v) i++ && (cout << d), f(x);
  cout << e;
}
template <typename T>
inline typename T::iterator minel(T& v) {
  return min_element(begin(v), end(v));
}
template <typename T>
inline typename T::iterator maxel(T& v) {
  return max_element(begin(v), end(v));
}
inline void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long pow_mod(long long a, long long k, long long m) {
  long long r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1) r = r * a % m;
  return r;
}
inline long long mod_inv(long long a, long long p) {
  return pow_mod(a, p - 2, p);
}
int bucket[2000002] = {};
int main() {
  int n = in();
  vector<int> v;
  inpt(v, n, in);
  uniq(v);
  revs(v);
  for (int x : v) {
    for (int i = x + 1; i <= 2000001; i++) {
      if (bucket[i]) break;
      bucket[i] = x;
    }
  }
  int maxi = 0;
  for (int x : v) {
    for (int i = x * 2; i <= 2000001; i += x) {
      maxi = max(maxi, bucket[i] % x);
    }
  }
  printf("%d\n", maxi);
  return 0;
}
