#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000050], num[200050];
bool vis[2000050];
inline void read(int &x) {
  x = 0;
  register char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int main() {
  read(n);
  register int ma = 0;
  for (register int i = 1; i <= n; i++) {
    read(num[i]);
    ma = max(num[i], ma);
    a[num[i]] = num[i];
  }
  for (register int i = 1; i <= 2 * ma + 1; i++) {
    if (!a[i]) a[i] = a[i - 1];
  }
  int ans = 0;
  for (register int i = 1; i <= n; i++) {
    if (vis[num[i]]) continue;
    vis[num[i]] = 1;
    for (register int j = 2;; j++) {
      if (num[i] * j >= 2 * ma + 1) break;
      ans = max(a[num[i] * j - 1] % num[i], ans);
    }
  }
  cout << ans << endl;
}
