from collections import deque
n, k = map(int, input().split())
g = [list(map(int, input())) for _ in range(2)]
check = [[-1] * n for _ in range(2)]
escape = False
q = deque()
q.append((0, 0, 0))
check[0][0] = 0
while q:
x, y, t = q.popleft()
for nx, ny in [(x, y-1), (x, y+1), (1-x, y+k)]:
if ny < 0:
continue
if ny >= n:
escape = True
continue
if g[nx][ny] == 0:
continue
if check[nx][ny] == -1:
q.append((nx, ny, t+1))
check[nx][ny] = 0
g[1][t] = g[0][t] = 0
if escape == True:
print(1)
else:
print(0)
한 줄씩 사라지는 것은 시간을 큐에 넣어서 그 칸을 다 0으로 만들어줌