main=interact$unlines.map(show.f.map read.words).lines;f x=c$zipWith(-)x$tail x;c l=head[n+1|n<-[0..],and$zipWith(==)l$map(l!!)(cycle[0..n])]