#include <bits/stdc++.h>
int main() {
  int mod = 0, n, i, num, j, arr[2000005] = {0}, max = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    arr[num] = num;
    if (num > max) max = num;
  }
  for (i = 1; i < 2 * max; i++)
    if (arr[i] == 0) arr[i] = arr[i - 1];
  for (i = max - 1; i > mod; i--)
    if (arr[i] == i)
      for (j = 2 * i - 1; j < 2 * max; j += i)
        mod = (mod - (arr[j] % i) > 0) ? mod : arr[j] % i;
  printf("%d\n", mod);
  return 0;
}
