#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 50;
const int MAXD = 12;
int n;
int d[MAXN];
int cnt[MAXD + 1];
int opt[MAXD], nopt;
int cur[MAXN], ncur;
int solve() {
  for (int i = (0); i <= (MAXD); ++i) cnt[i] = 0;
  for (int i = (0); i < (n); ++i) ++cnt[d[i]];
  for (int i = (0); i <= (MAXD); ++i)
    if (cnt[i] >= (i == 0 ? 1 : i == MAXD ? 2 : 3)) return 0;
  nopt = 0;
  for (int i = (1); i <= (MAXD - 1); ++i)
    if (cnt[i] == 1) opt[nopt++] = i;
  int ret = 0;
  for (int mask = (0); mask < (1 << nopt); ++mask) {
    ncur = 0;
    for (int i = (1); i <= (MAXD - 1); ++i)
      if (cnt[i] == 2) cur[ncur++] = i, cur[ncur++] = 2 * MAXD - i;
    for (int i = (0); i < (nopt); ++i)
      cur[ncur++] = (mask & (1 << i)) == 0 ? opt[i] : 2 * MAXD - opt[i];
    if (cnt[MAXD] == 1) cur[ncur++] = MAXD;
    assert(ncur == n);
    sort(cur, cur + ncur);
    int curval = INT_MAX;
    for (int i = (0); i < (n); ++i)
      curval = min(curval, (cur[(i + 1) % n] - cur[i] + 2 * MAXD) % (2 * MAXD));
    if (curval > ret) ret = curval;
  }
  return ret;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &d[i]);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
