#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num[200005], maxn = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    maxn = max(num[i], maxn);
  }
  sort(num, num + n);
  n = unique(num, num + n) - num;
  for (int i = 0; i < n; i++) {
    for (int j = num[i]; j - num[i] <= maxn; j += num[i]) {
      int p = lower_bound(num, num + n, j) - num - 1;
      if (p >= 0 && num[p] >= num[i]) ans = max(ans, num[p] % num[i]);
    }
  }
  printf("%d", ans);
  return 0;
}
