#include <bits/stdc++.h>
using namespace std;
int n, a[3000000], i, j, x, last, ans, p[300000];
bool b[3000000] = {};
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    a[x] = x;
  }
  for (i = 0; i <= 2000000; i++) {
    if (!a[i]) a[i] = a[i - 1];
  }
  for (i = 1; i <= 1000000; i++) {
    if (a[i] == i) {
      for (j = i * 2 - 1; j <= 2000000; j += i) {
        ans = max(ans, a[j] % i);
      }
    }
  }
  cout << ans;
}
