n,k=map(int,input().split()) A=list(map(int,input().split())) C=list(map(int,input().split())) X=[0]*51 def m(A,B): for i in range(1,len(A)): if A[i]: for j in range(max(1,i-k),min(len(A)-1,i+k)+1): if B[j]: return True return False for i in range(n): Y=X[:] Y[C[i]]=1 Y[0]=A[i] C[i]=Y for i in range(n+2): for j in range(n): C[j] C[(j+1)%n] if m(C[j],C[(j+1)%n]): C[(j+1)%n][0]+=C[j][0] C[j][0]=0 for ii in range(1,51): if C[j][ii] or C[(j+1)%n][ii]: C[j][ii]=1 C[(j+1)%n][ii]=1 ans=0 for i in range(n): ans=max(ans,C[i][0]) print(ans) #print(C)