while True: try: l1=list(map(int,input().strip().split())) a=l1[0] if a==0: continue b=l1[1] list1=[] list2=[] for i in range(a): list3=list(map(int,input().strip().split())) list1.append(list3) for j in range(a): list3=list(map(int,input().strip().split())) list2.append(list3) num=0 for i in range(a): for j in range(b): num=list1[i][j]+list2[i][j] list1[i][j]=num count=0 for i in range(a): flag=0 for j in range(b): if list1[i][j]==0: flag=1 else: flag=0 break if flag==1: count+=1 for i in range(b): flag=0 for j in range(a): if list1[j][i]==0: flag=1 else: flag=0 break if flag==1: count+=1 print(count) except EOFError: break