#include <bits/stdc++.h>
using namespace std;
int pos[4000000];
int vis[5000000];
int a[500000];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int tot = 0;
    int maxn = 0;
    memset(vis, -1, sizeof(vis));
    memset(pos, -1, sizeof(pos));
    vis[1] = 1;
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      vis[x] = x;
    }
    int output = 0;
    for (int i = 1; i <= 2000050; i++)
      if (vis[i] == -1) vis[i] = vis[i - 1];
    for (int i = 1; i <= 1000050; i++) {
      if (vis[i] == i) {
        for (int j = i * 2; j <= 2000050; j += i) {
          if (vis[j - 1] > i) output = max(output, vis[j - 1] % i);
        }
      }
    }
    printf("%d\n", output);
  }
}
