main=print.f.map read.words=<<getContents
f(n:ds)=minimum[g x y|(i,x)<-ids, (j,y)<-ids, i/=j] where ids=zip[0..]$0:ds
g x y=maximum$map h[(a,b)|a<-[x,24-x],b<-[y,24-y]]
h(x,y)=min d(24-d)where d=abs(y-x)