#include <bits/stdc++.h>
using namespace std;
int A[2000005];
int n, ans, t, maxi;
int main() {
  cin >> n;
  for (int i = (1); i <= (n); i += (1)) cin >> t, A[t] = t, maxi = max(t, maxi);
  for (int i = (2); i <= (2 * maxi); i += (1)) A[i] ? false : A[i] = A[i - 1];
  for (int i = (2); i <= (maxi); i += (1))
    if (A[i] == i)
      for (int j = (i * 2 - 1); j <= (2 * maxi); j += (i)) {
        if (A[j] == j) {
          ans = A[j] % i;
          break;
        }
        ans = max(ans, A[j] % i);
      }
  printf("%d", ans);
}
