#include <bits/stdc++.h>
using namespace std;
int const MAXN = 200010;
int a[MAXN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i && a[i] == a[i - 1]) continue;
    for (int j = 2 * a[i]; j <= a[n - 1]; j += a[i]) {
      int p = lower_bound(a, a + n, j) - a;
      if (p == n) break;
      ans = max(ans, a[p - 1] % a[i]);
    }
    ans = max(ans, a[n - 1] % a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
