#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,people,total=0;
cin>>a>>b;
cin>>people;
int ptr[people][100];
for(int i=0;i<people;i++)
for(int j=0;j<100;j++){
cin>>ptr[i][j];
if(ptr[i][j]==0)
break;
}
int buy_a,buy_b;
for(int i=0;i<people;i++){
buy_a=0;
buy_b=0;
for(int j=0;j<100;j++){
if(ptr[i][j]==a )
buy_a++;
if(ptr[i][j]==b)
buy_b++;
if(ptr[i][j]==(-1*a))
buy_a--;
if(ptr[i][j]==(-1*b))
buy_b--;
if(ptr[i][j]==0)
break;
}
if(buy_a>=1 and buy_b>=1)
total++;
}
cout<<total;
return 0;
}