#include <bits/stdc++.h>
using namespace std;
int n, a[300010], b[3000010], ans = 0, m = 0, l;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  l = unique(a + 1, a + n + 1) - a - 1;
  for (int i = 1; i <= l; i++)
    for (int j = a[i]; j <= a[l]; j += a[i])
      ans = max(ans, a[lower_bound(a + 1, a + l + 1, j + a[i]) - a - 1] % a[i]);
  cout << ans << endl;
  return 0;
}
