#include <bits/stdc++.h>
using namespace std;
bool is[1000005];
int a[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  int ma = a[n - 1];
  int temp = unique(a, a + n) - a;
  int fin = 0;
  for (int i = 0; i < temp; i++) {
    for (int j = 1; a[i] * j <= ma; j++) {
      int r = a[i] * (j + 1);
      fin = max(fin, a[lower_bound(a, a + temp, r) - a - 1] - a[i] * j);
    }
  }
  cout << fin << endl;
}
