#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int a[maxn], n, mx, ans;
void check(int x, int pos) {
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[mid] < x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  ans = max(ans, a[l - 1] % pos);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), mx = max(mx, a[i]);
  sort(a + 1, a + 1 + n);
  a[n + 1] = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i + 1]) {
      for (int j = 2; j * a[i] <= mx; j++) check(j * a[i], a[i]);
    }
    ans = max(ans, mx % a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
