#include <bits/stdc++.h>
using namespace std;
const int N = 2e+5 + 7;
int arr[N];
int bin(int l, int r, int key) {
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (arr[m] >= key)
      r = m - 1;
    else
      l = m + 1;
  }
  return r;
}
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", arr + i);
  sort(arr, arr + n);
  n = unique(arr, arr + n) - arr;
  for (int i = 0; i < n; ++i)
    for (int j = 2; arr[i] != 1 && arr[i] <= arr[n - 1] / (j - 1); ++j)
      ans = max(ans, arr[bin(i + 1, n - 1, arr[i] * j)] % arr[i]);
  printf("%d\n", ans);
  return 0;
}
