#include <bits/stdc++.h>
using namespace std;
int a[211111];
int mp[1111111];
int visit[1111111];
int maxx = 0;
int main() {
  int ans = 0;
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]] = a[i];
  }
  sort(a, a + n);
  maxx = a[n - 1];
  for (i = 0; i <= maxx; i++)
    if (mp[i] != i) mp[i] = mp[i - 1];
  for (i = 0; i < n; i++) {
    if (visit[a[i]]) continue;
    visit[a[i]] = 1;
    for (int j = a[i] * 2; j <= maxx; j += a[i]) {
      ans = max(ans, mp[j - 1] % a[i]);
    }
    ans = max(maxx % a[i], ans);
  }
  printf("%d\n", ans);
}
