#include <bits/stdc++.h>
using namespace std;
template <class T>
void print_array(T a[], int size) {
  for (int i = 0; i < size; i++) cout << a[i] << " ";
  cout << endl;
}
template <class T>
void print_array_v(T &a) {
  int size = a.size();
  for (int i = 0; i < size; i++) cout << a[i] << " ";
  cout << endl;
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1 || (i != 0 && a[i] == a[i - 1])) continue;
    for (int j = 2 * a[i]; j <= (a[n - 1] + a[i]); j += a[i]) {
      long long tmp = *(lower_bound(a, a + n, j) - 1);
      ans = max(ans, tmp % a[i]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
