#include <bits/stdc++.h>
int Data[200006];
int N;
int cmp(const void* a, const void* b) {
  int A = *(int*)a;
  int B = *(int*)b;
  if (A > B)
    return 1;
  else if (A == B)
    return 0;
  else
    return -1;
}
int Solve(int A) {
  int l = 0;
  int r = N - 1;
  int mid = (l + r) / 2;
  while (Data[mid] != A && l != r) {
    if (Data[mid] < A)
      l = mid + 1;
    else
      r = mid;
    mid = (l + r) / 2;
  }
  if (Data[mid] == A)
    return mid;
  else
    return l;
}
int main(void) {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &Data[i]);
  qsort(Data, N, sizeof(int), cmp);
  int mod = 0;
  int NN = 1;
  for (int i = 1; i < N; i++) {
    if (Data[i] != Data[i - 1]) Data[NN++] = Data[i];
  }
  N = NN;
  for (int i = N - 1; i >= 1 && Data[i] > mod; i--) {
    int A = Data[i] / Data[i - 1] + 1;
    while (Data[i] / A > mod) {
      int Get = Solve(Data[i] / A + 1);
      if (Get < i) {
        int M = Data[i] % Data[Get];
        if (M > mod) {
          mod = M;
        }
      }
      A++;
    }
  }
  printf("%d\n", mod);
  return 0;
}
