#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int num[maxn], ans;
void Solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", num + i);
  sort(num + 1, num + 1 + n);
  int nn = unique(num + 1, num + 1 + n) - (num + 1);
  for (int i = 1; i <= nn; i++) {
    int j = num[i] << 1;
    int pos = lower_bound(num + 1, num + 1 + nn, j) - num;
    while (num[pos - 1] < j && pos <= nn) {
      ans = max(ans, num[pos - 1] % num[i]);
      pos = lower_bound(num + pos + 1, num + 1 + nn, j) - num;
      j += num[i];
    }
    ans = max(ans, num[pos - 1] % num[i]);
  }
  printf("%d", ans);
}
int main() {
  Solve();
  getchar();
  getchar();
  return 0;
}
