#include <bits/stdc++.h>
using namespace std;
bool was[1000005];
int n;
int arr[2000005];
int main() {
  scanf("%d", &n);
  int x;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    arr[x] = x;
  }
  for (int i = 2; i <= 2000000; i++)
    if (arr[i] == 0) arr[i] = arr[i - 1];
  int ans = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (arr[i] == i)
      for (int j = 2 * i - 1; j <= 2000000; j += i) ans = max(ans, arr[j] % i);
  }
  printf("%d", ans);
}
