program traseu;
var f:text;
n, nrcasa, i, v, contor:integer;
function suma(m:integer):integer;
var s:integer;
begin
s:=0;
while (m<>0) do
begin
s:=s+m mod 10;
m:=m div 10;
end;
suma:=s;
end;
BEGIN
assign(f,'numere.in'); reset(f);
readln(f,v, n);
for i:=1 to n do
begin
readln(f, nrcasa);
if suma(nrcasa)=v then contor:=contor+1;
end;
writeln(contor);
close(f);
end.