#include <bits/stdc++.h>
using namespace std;
int N = 1000000;
vector<int> a(2000005, 0), last(2000005, -1);
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, i, j, k, x, y, z;
  cin >> n;
  for (i = (0); i < (n); ++i) {
    cin >> x;
    a[x] = 1;
  }
  for (i = (1); i < (2 * N + 1); ++i) {
    if (a[i])
      last[i] = i;
    else
      last[i] = last[i - 1];
  }
  int ans = 0;
  for (i = (2); i < (N + 1); ++i) {
    if (a[i]) {
      j = 2 * i;
      while (j <= 2 * N) {
        ans = max(ans, last[j - 1] % i);
        j += i;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
