#include <cstdio>
#include <algorithm>
const int MAXN = 1e5 + 10;
int n;
int a[MAXN], pos[MAXN];
int ans;
int main() {
#ifdef LOCAL
freopen("!input.in", "r", stdin);
freopen("!output.out", "w", stdout);
#else
freopen("arrayy.in", "r", stdin);
freopen("arrayy.out", "w", stdout);
#endif
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
pos[i] = i;
}
do {
int x = a[pos[1]];
for (int i = 2; i <= n; ++i) {
x = x % a[pos[i]];
}
ans = std::max(ans, x);
} while (std::next_permutation(pos + 1, pos + n + 1));
printf("%d\n", ans);
return 0;
}