#include <bits/stdc++.h>
using namespace std;
const int N = 2000500;
bool u[N], was[N];
int n, ans, mx[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    u[x] = 1;
  }
  for (int i = 1; i < N; i++) {
    mx[i] = (u[i - 1] ? i - 1 : mx[i - 1]);
  }
  for (int i = 1; i < N; i++) {
    if (u[i] && !was[i]) {
      for (int j = 2 * i; j < N; j += i) {
        int cur = mx[j];
        if (cur) ans = max(ans, cur % i);
      }
      was[i] = 1;
    }
  }
  printf("%d", ans);
}
