#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int b[N];
int main() {
  int n;
  scanf("%d", &n);
  int val;
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    b[val] = val;
  }
  for (int i = 0; i < N; i++) {
    b[i] = max(b[i], b[i - 1]);
  }
  int ans = 0;
  for (int i = 2; i < N; i++) {
    if (b[i] == i) {
      for (int j = i - 1; j < N; j += i) {
        if (j < N && i < b[j] && ans < b[j] % i) {
          ans = b[j] % i;
        }
      }
    }
  }
  printf("%d\012", ans);
  return 0;
}
