#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  ios::sync_with_stdio(0);
  int n, maxi = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxi = max(maxi, a[i]);
  }
  sort(a, a + n);
  n = unique(a, a + n) - a;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = a[i] << 1; j <= maxi + a[i]; j += a[i]) {
      int pos = lower_bound(a + i + 1, a + n, j) - a;
      ans = max(ans, a[pos - 1] % a[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
