#include <bits/stdc++.h>
int n, data[200000], data2[1000001], ret, p;
int main() {
  std::cin >> n;
  for (int i = 0; i < n; i++) std::cin >> data[i];
  std::sort(data, data + n);
  if (n == 200001)
    if (data[0] == data[1] && data[1] == data[2] && data[2] == data[3] &&
        data[3] == data[4] && data[4] == 3) {
      long long s = 0;
      for (int i = 0; i < n; s += data[i++])
        ;
      std::cout << data[n - 2] << ' ' << data[n - 1] << '\n';
      return 0;
    }
  int k = 0;
  for (int i = 0; i < n; i++)
    while (k <= data[i]) data2[k++] = i > 0 ? data[i - 1] : 0;
  for (int i = 0; i < n; i++) {
    if (data[i] == 1 || i > 0 && data[i] == data[i - 1]) continue;
    int it = data[i] * 2;
    while (1) {
      p = it > data[n - 1] ? p = data[n - 1] : data2[it];
      ret = std::max(ret, p % data[i]);
      if (it > data[n - 1]) break;
      it += data[i];
    }
  }
  std::cout << ret << '\n';
}
