#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
/*#if !defined(YCM) && 0
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")
#include <stdio.h>
#endif*/
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
    freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
    //freopen("/home/alexandero/ClionProjects/ACM/output.txt", "w", stdout);
    //freopen("out.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
    cout.sync_with_stdio(0);
    cin.tie(0);
    precalc();
    cout.precision(10);
    cout << fixed;
    //cin >> t;
    int testNum = 1;
    while (t--) {
        //cout << "Case #" << testNum++ << ": ";
        //cerr << testNum << endl;
        solve(true);
        //cerr << testNum - 1 << endl;
    }
    cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
    cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

    return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {}

//#define int li
//const int mod = 1000000007;

vector<int> dsu;

void init(int n) {
    dsu.resize(n);
    for (int i= 0; i < n; ++i) {
        dsu[i] = i;
    }
}

int find_set(int v) {
    if (dsu[v] == v) {
        return v;
    }
    return dsu[v] = find_set(dsu[v]);
}

void merge(int q, int w) {
    q = find_set(q);
    w = find_set(w);
    dsu[w] = q;
}

void solve(bool read) {
    int n;
    cin >> n;
    ++n;
    vector<int> d(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> d[i + 1];
    }
    for (int s = 0; s < 12; ++s) {
        init(n);
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int diff_dist = min(d[i] + d[j], 24 - d[i] - d[j]);
                if (diff_dist < s) {
                    merge(i, j);
                }
            }
        }
        vector<vector<int>> g(n);
        bool flag = true;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int same_dist = abs(d[i] - d[j]);
                if (same_dist < s) {
                    int from = find_set(i);
                    int to = find_set(j);
                    if (from == to) {
                        flag = false;
                        break;
                    }
                    g[find_set(i)].push_back(find_set(j));
                    g[find_set(j)].push_back(find_set(i));
                }
            }
        }
        vector<int> col(n, -1);
        for (int i = 0; i < n; ++i) {
            if (col[i] == -1) {
                col[i] = 0;
                queue<int> q;
                q.push(i);
                while (!q.empty()) {
                    int v = q.front();
                    q.pop();
                    for (int to : g[v]) {
                        if (col[to] == -1) {
                            col[to] = col[v] ^ 1;
                            q.push(to);
                        } else if (col[to] == col[v]) {
                            flag = false;
                            break;
                        }
                    }
                }
            }
        }
        if (!flag) {
            cout << s - 1 << endl;
            return;
        }
    }
    cout << 11 << endl;
}

Measured memory_bytes: 256