$c=<>;$n=<>;$/=$";@d=(0,(-1)x$c);for$a(<>){($==$d[$_-$a])>=0&(8**9&$d[$_])>++$=and$d[$_]=$=for$a..$c}print$d[$c]