$/=$%=<>;$_=<>;s/\./ /;$e="(.{$%})?";($a,$b)=(v9,A..Z,a..g)[$i,$i+1],s/\.$e? | $e?\./ $1$2 /s||s/$a$e#/$a$1$b/s|s/#$e$a/$b$1$a/s||$i++until/\w$e?\.|\.$e\w/s;print$i+1