$_=<>;print<>!~/.$/,eval("1+grep s/$`$&/$&/,(\$_)x$<")%2001-1