program time_gap
  implicit none
  integer :: n, d(50) = 0, p(0:12) = 0, m = 48, i, j
  logical :: t(0:47) = .true., f = .false.
  read(*,*) n
  read(*,*) d(1:n)
  p(0) = 1
  do i = 1, n
    p(d(i)) = p(d(i))+1
  end do
  if (p(0) > 1 .or. p(12) > 1 .or. any(p(1:11) > 2)) then
    write(*,'(i0)') 0
    stop
  end if
  t(0) = .false.
  if (p(12) == 1) t(12) = .false.
  do i = 1, 11
    if (p(i) == 0) cycle
    if (p(i) == 2) then
      t(i) = .false.
      t(24-i) = .false.
      cycle
    end if
    if (f) then
      t(i) = .false.
    else
      t(24-i) = .false.
    end if
    f = .not.f
  end do
  t(24:47) = t(0:23)
  i = 0
  j = 1
  do while (i < 24)
    do while (t(j))
      j = j+1
    end do
    m = min(m,j-i)
    i = j
    j = j+1
  end do
  write(*,'(i0)') m
end program time_gap