#include <bits/stdc++.h>
using namespace std;
int N, mx, res;
int A[200005];
int h[2000005];
int main() {
  int i, j, a, b;
  scanf("%d ", &N);
  for (i = 1; i <= N; i++) {
    scanf("%d", A + i);
    h[A[i]] = A[i];
    mx = max(mx, A[i]);
  }
  for (i = 1; i <= 2 * mx; i++)
    if (!h[i]) h[i] = h[i - 1];
  sort(A + 1, A + N + 1);
  N = unique(A + 1, A + N + 1) - A - 1;
  for (i = 1; i <= N; i++)
    for (j = A[i]; j <= 2 * mx; j += A[i]) {
      if (A[i] > h[j - 1] && h[j - 1])
        res = max(res, A[i] % h[j - 1]);
      else
        res = max(res, h[j - 1] % A[i]);
    }
  cout << res << endl;
}
