import Data.List as L

main=do
    n<-L.map read . words<$>getLine::IO[Integer]
    (m1:m2:m)<-L.map read . words<$>getLine::IO[Integer]
    print $ if fst (L.foldl' (\a c-> ((fst a)&&(((snd a)==0 && m1==c)||((snd a)==1 && m2==c)), if (snd a) == 1 then 0 else 1)) (True, 0) m) 
        then if m1/=m2 then 0 else 2
        else 1