#include <bits/stdc++.h>
using namespace std;
bool have[2000010];
int nearest[2000010];
int main() {
  memset(have, 0, sizeof(have));
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    have[a] = true;
  }
  nearest[0] = 0;
  for (int i = 0; i < 2000010; i++) {
    if (have[i])
      nearest[i] = 0;
    else
      nearest[i] = nearest[i - 1] + 1;
  }
  int res = 0;
  for (int i = 2; i < 2000010; i++)
    if (have[i])
      for (int j = i + i; j < 2000010; j += i) {
        res = max(res, i - 1 - nearest[j - 1]);
      }
  cout << res << "\n";
  return 0;
}
