#[allow(unused_imports)]
use std::cmp::Ordering;

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get {
    ([$t: ty]) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

struct HopcroftKarp {
    l_size: usize,
    r_size: usize,
    list: Vec<Vec<usize>>,
    seen: Vec<bool>,
    matched: Vec<bool>,
    level: Vec<isize>,
    matching: Vec<usize>,
}
impl HopcroftKarp {
    fn new(l: usize, r: usize) -> Self {
        HopcroftKarp {
            l_size: l,
            r_size: r,
            list: vec![Vec::new(); l],
            seen: vec![false; l],
            matched: vec![false; l],
            level: vec![-1; l + 1],
            matching: vec![l; r],
        }
    }
    fn add_edge(&mut self, from: usize, to: usize) {
        self.list[from].push(to);
    }
    fn bfs(&mut self) {
        let mut queue = VecDeque::new();
        for left in 0..self.l_size {
            self.level[left] = -1;
            if !self.matched[left] {
                queue.push_back(left);
                self.level[left] = 0;
            }
        }
        self.level[self.l_size] = self.l_size as isize;
        while let Some(left) = queue.pop_front() {
            for i in 0..self.list[left].len() {
                let right = self.list[left][i];
                let next = self.matching[right];
                if self.level[next] == -1 {
                    self.level[next] = self.level[left] + 1;
                    queue.push_back(next);
                }
            }
        }
    }
    fn dfs(&mut self, left: usize) -> bool {
        if left == self.l_size {
            return true;
        } else if self.seen[left] {
            return false;
        }
        self.seen[left] = true;
        for i in 0..self.list[left].len() {
            let right = self.list[left][i];
            let next = self.matching[right];
            if self.level[next] > self.level[left] && self.dfs(next) {
                self.matching[right] = left;
                return true;
            }
        }
        false
    }
    fn solve(&mut self) -> usize {
        self.seen = vec![false; self.l_size];
        self.matched = vec![false; self.l_size];
        self.level = vec![-1; self.l_size + 1];
        self.matching = vec![self.l_size; self.r_size];
        let mut res = 0;
        loop {
            self.bfs();
            self.seen = vec![false; self.l_size];
            let mut finished = true;
            for left in 0..self.l_size {
                if !self.matched[left] && self.dfs(left) {
                    self.matched[left] = true;
                    res += 1;
                    finished = false;
                }
            }
            if finished {
                break;
            }
        }
        res
    }
}

fn solve() {
    let n = get!(usize);
    let d = get!([usize]);

    if n >= 24 {
        println!("0");
        return;
    }

    let mut mx = 0;
    for i in 0..1usize << 23 {
        if i.count_ones() as usize != n {
            continue;
        }

        let mut set = BTreeSet::new();
        set.insert(0);
        for j in 0..23 {
            if (i >> j) & 1 == 1 {
                set.insert(j + 1);
            }
        }

        let mut matching = HopcroftKarp::new(n + 1, 24);
        matching.add_edge(0, 0);
        let mut flag = false;
        for j in 0..n {
            if !set.contains(&d[j]) && !set.contains(&(24 - d[j])) {
                flag = true;
                break;
            }
            if d[j] == 12 {
                if set.contains(&d[j]) {
                    matching.add_edge(j + 1, d[j]);
                }
            } else {
                if set.contains(&d[j]) {
                    matching.add_edge(j + 1, d[j]);
                }
                if set.contains(&(24 - d[j])) {
                    matching.add_edge(j + 1, 24 - d[j]);
                }
            }
        }
        if flag {
            continue;
        }
        if matching.solve() < n + 1 {
            continue;
        }
        let vec = set.into_iter().collect::<Vec<_>>();
        let mut mn = std::usize::MAX;
        for j in 0..vec.len() - 1 {
            mn = min!(mn, vec[j + 1] - vec[j]);
        }
        mn = min!(mn, 24 + vec[0] - vec[vec.len() - 1]);
        mx = max!(mn, mx);
    }
    println!("{}", mx);
}


Measured memory_bytes: 8572