#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[200009], ans = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++)
    if (a[i] != a[i + 1])
      for (int k = 2 * a[i]; k <= a[n - 1] + a[i]; k += a[i]) {
        int l = i + 1, r = n - 1;
        while (l != r) {
          int m = (l + r + 1) / 2;
          if (a[m] >= k)
            r = m - 1;
          else
            l = m;
        }
        ans = max(ans, a[l] % a[i]);
      }
  cout << ans;
  return 0;
}
