#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[2000005];
int ans = 0;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = a[i];
  }
  for (int i = 1; i <= 2000000; i++) {
    b[i] = max(b[i], b[i - 1]);
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int k = a[i];
    if (i && k == a[i - 1]) continue;
    for (int j = 2 * k; j <= 2000000; j += k) {
      ans = max(ans, b[j - 1] % k);
    }
  }
  printf("%d ", ans);
}
