gets;k=->i{z=$_.split.map{|e|e.to_i%i};z.sort[1]!=z[1]&&z|[]==z} puts k[1e4]?:INF:(1..1e3).count&k