#include <bits/stdc++.h>
using namespace std;
int a[201000];
int vis[2010000];
int main() {
  int n;
  cin >> n;
  long long m = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > m) m = a[i];
    vis[a[i]] = a[i];
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= 2 * m; i++) {
    if (vis[i] == 0) vis[i] = vis[i - 1];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) continue;
    for (int j = 2 * a[i]; j <= m + a[i]; j += a[i]) {
      if (vis[j - 1] % a[i] > ans && vis[j - 1] > a[i]) {
        ans = vis[j - 1] % a[i];
      }
    }
  }
  cout << ans << endl;
}
