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