#print "str1 >>>> " #探したい文字列
str1 = gets.chomp
#print "n >>>> " #指輪の数
n = gets.chomp.to_i
cnt = 0
for i in 1..n
  #print "str2[#{i}]"
  str2 = gets.chomp
  if (str2+str2).include?(str1)
    cnt += 1;
  end
end

print cnt,"\n";

