#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  sort(a, a + n);
  n = unique(a, a + n) - a;
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = (a[i] << 1); j <= mx * 2; j += a[i]) {
      int id = upper_bound(a, a + n, j - 1) - a - 1;
      if (a[id] >= a[i]) {
        ret = max(ret, a[id] % a[i]);
      }
    }
  }
  cout << ret;
  return 0;
}
