Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.

In the city in which Alice and Bob live, the first metro line is being built. This metro line contains $n$ stations numbered from $1$ to $n$. Bob lives near the station with number $1$, while Alice lives near the station with number $s$. The metro line has two tracks. Trains on the first track go from the station $1$ to the station $n$ and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that.

Some stations are not yet open at all and some are only partially open — for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it.

When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport.


-----Input-----

The first line contains two integers $n$ and $s$ ($2 \le s \le n \le 1000$) — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station $1$.

Next lines describe information about closed and open stations.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($a_i = 0$ or $a_i = 1$). If $a_i = 1$, then the $i$-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track.

The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($b_i = 0$ or $b_i = 1$). If $b_i = 1$, then the $i$-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track.


-----Output-----

Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise.

You can print each letter in any case (upper or lower).


-----Examples-----
Input
5 3
1 1 1 1 1
1 1 1 1 1

Output
YES

Input
5 4
1 0 0 0 1
0 1 1 1 1

Output
YES

Input
5 2
0 1 1 1 1
1 1 1 1 1

Output
NO



-----Note-----

In the first example, all stations are opened, so Bob can simply travel to the station with number $3$.

In the second example, Bob should travel to the station $5$ first, switch to the second track and travel to the station $4$ then.

In the third example, Bob simply can't enter the train going in the direction of Alice's home.

Difficulty: interview

Starter code:

Solutions:
# map(int, input().split())
# list(map(int, input().split()))
n, m = list(map(int, input().split()))
m -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
    print("NO")
    return
elif a[m] == 1:
    print("YES")
    return
elif b[m] == 0:
    print("NO")
    return
else:
    for i in range(m, n):
        if a[i] and b[i]:
            print("YES")
            return
    print("NO")


import sys
import string
from math import gcd
import getpass
import math
from decimal import Decimal
import pprint


def ria():
    return [int(i) for i in input().split()]


if getpass.getuser() != 'frohenk':
    filename = 'half'
    # sys.stdin = open('input.txt')
    # sys.stdout = open('output.txt', 'w')
else:
    sys.stdin = open('input.txt')
    # sys.stdin.close()
# sys.stdout = open('output.txt', 'w')


n, s = ria()
s -= 1
ar1 = ria()
ar2 = ria()
if ar1[0] == 0:
    print('NO')
    return

if ar1[s] == 1:
    print('YES')
    return
if ar2[s] == 1:
    for i in range(s, n):
        if ar2[i] == 1 and ar1[i] == 1:
            print('YES')
            return
print('NO')

n,s=map(int,input().split())
a=[int(s) for s in input().split()]
b=[int(s) for s in input().split()]
if a[0]==0:
    print('NO')
else:
    if a[s-1]==1:
        print('YES')
    else:
        if b[s-1]==0:
            print('NO')
        else:
            for i in range(s,n):
                if a[i]==1 and b[i]==1:
                    print('YES')
                    break
            else:
                print('NO')

n, s = list(map(int, input().strip().split()))
ab = list(map(int, input().strip().split()))
bb = list(map(int, input().strip().split()))

s -= 1

if ab[0] == 0:
	print('NO')
else:
	if ab[s] == 1:
		print('YES')
	else:
		if bb[s] == 1:	
			for i in range(s+1, n):
				if ab[i] == 1 and bb[i] == 1:
					print('YES')
					break
			else:
				print('NO')
		else:
			print('NO')

#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, S = getIntList()
z1 = getIntList()
z2 = getIntList()
#print(N)

if z1[0] ==0:
    print('NO')
    return

if z1[S-1] ==1:
    print('YES')
    return

if z2[S-1]==0:
    print('NO')
    return

for i in range(S-1, N):
    if z1[i] ==1 and z2[i]==1:
        print('YES')
        return

print('NO')








n, s = list(map(int, input().split()))
s -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
    print("NO")
elif a[s] == 1:
    print("YES")
elif b[s] == 0:
    print("NO")
elif any([x[0] == x[1] == 1 for x in zip(a[s:], b[s:])]):
    print("YES")
else:
    print("NO")




import sys

input = sys.stdin.readline

n, s = map(int, input().split())

fw = [0] + list(map(int, input().split()))
bw = [0] + list(map(int, input().split()))

if fw[1] == 0:
    print("NO")
elif fw[s] == 0 and bw[s] == 0:
    print("NO")
else:
    if fw[s] == 1:
        print("YES")
    else:
        valid = False 
        for i in range(s+1, len(fw)):
            if fw[i] and bw[i]:
                valid = True
        if valid:
            print("YES")
        else:
            print("NO")

n, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
    print("NO")
else:
    if a[s - 1] == 1:
        print("YES")
    elif b[s - 1] == 0:
        print("NO")
    else:
        for i in range(s, n):
            if a[i] == 1 and b[i] == 1:
                print("YES")
                break
        else:
            print("NO")

n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s -= 1
if a[0] == 0:
    print('NO')
elif a[s] == 0 and b[s] == 0:
    print('NO')
elif a[s] == 0:
    ok = False
    for i in range(s + 1, n):
        if a[i] == 1 and b[i] == 1:
            print('YES')
            ok = True
            break
    if not ok:
        print('NO')
else:
    print('YES')


def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())

n, s = mi()
a = li()
b = li()
s -= 1

ok = 1
if s == 0:
    ok = 1
elif a[0] == 0:
    ok = 0
elif a[s]:
    ok = 1
elif b[s] == 0:
    ok = 0
else:
    ok = any(a[i] == 1 and b[i] == 1 for i in range(s + 1, n))
print('YES' if ok else 'NO')


import sys

n, s = list(map(int, input().split()))

a = list(map(int, input().split()))
b = list(map(int, input().split()))

if a[0] == 0:
    print('NO')
    return

if a[s - 1]:
    print('YES')
    return

if b[s - 1]:
    for i in range(s, n):
        if a[i] and b[i]:
            print('YES')
            return

print('NO')


n, s = [int(x) for x in input().split()]
lst1 = [int(x) for x in input().split()]
lst2 = [int(x) for x in input().split()]

if lst1[0]==1 and lst1[s-1]==1:
        print("YES")
        return
elif lst1[0]==0 or (lst1[s-1]==0 and lst2[s-1]==0):
        print("NO")
        return
for i in range(s,n):
        if (lst1[i]==1 and lst2[i]==1):
                print("YES")
                return
print("NO")


n, s = map(int, input().split(' '))

a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

solution = False

if(a[0] == 1):
  if(a[s - 1] == 1):
    solution = True
  elif(b[s - 1] == 1):
    for i in range(s, n):
      if(a[i] == 1 and b[i] == 1):
        solution = True
        break

if solution:
  print("YES")
else:
  print("NO")

n, s = list(map(int, input().split()))
a = [int(el) for el in input().split()]
b = [int(el) for el in input().split()]
s -= 1
if (a[0] == 0) or (a[s] == 0 and b[s] == 0):
    print('NO')
else:
    if a[s] == 1:
        print('YES')
    else:
        ss = 'NO'
        for i in range(s, n):
            if a[i] + b[i] == 2:
                ss = 'YES'
        print(ss)


n,s = map(int,input().split())

a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

if a[0] == 0:
    print('NO')
else:
    if a[s-1] == 1:
        print('YES')
    else:
        if b[s-1] == 0:
            print('NO')
        else:
            for i in range(s,n):
                if a[i]==1 and b[i]==1:
                    print('YES')
                    return
            else:
                print('NO')

def solve(a, b, s, n):
    if not a[0]:
        return "NO"
    if a[s-1]:
        return "YES"
    if b[s-1]:
        for i in range(s, n):
            if a[i] and b[i]:
                return "YES"
    return "NO"


def main():
    n, s = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    print(solve(a, b, s, n))


main()


# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import itertools
import sys

"""
created by shhuan at 2018/11/10 22:33

"""

N, M = list(map(int, input().split()))

A = [True if int(x) == 1 else False for x in input().split()]
B = [True if int(x) == 1 else False for x in input().split()]


if not A[M-1] and not B[M-1]:
    print('NO')
elif not A[0]:
    print('NO')
elif A[M-1]:
    print('YES')
else:
    if B[M-1]:
        for i in range(M, N):
            if A[i] and B[i]:
                print('YES')
                return

    print('NO')



n,s=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
if a[0] != 1:
	print("NO")
elif [0]*n == a:
	print("NO")
else:
	if a[s-1] == 1:
		print("YES")
	else:
		if b[s-1] == 0:
			print("NO")
		else:
			flag=0
			for i in range(s,n):
				if a[i]==1 and b[i]==1:
					print("YES")
					flag=1
					break
			if flag==0:
				print("NO")
				


def reachable(s, l, r):
    if not r[0]:
        return False
    if r[s]:
        return True
    if not l[s]:
        return False
    return any([arg[0] == 1 and arg[1] == 1 for arg in zip(r[s:], l[s:])])


n, s = list(map(int, input().split(' ')))
r = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
print('YES' if reachable(s-1, l, r) else 'NO')


from bisect import bisect_right as br
from bisect import bisect_left as bl
import sys
MAX = sys.maxsize
MAXN = 10**6+10
def isprime(n):
    n = abs(int(n))
    if n < 2:
        return False
    if n == 2: 
        return True    
    if not n & 1: 
        return False
    for x in range(3, int(n**0.5) + 1, 2):
        if n % x == 0:
            return False
    return True

def mhd(a,b,x,y):
    return abs(a-x)+abs(b-y)

def numIN():
    return(map(int,sys.stdin.readline().strip().split()))

def charIN():
    return(sys.stdin.readline().strip().split())

n,s = numIN()
a = list(numIN())
b = list(numIN())

if not a[0] or (a[s-1]==0 and b[s-1]==0):
	print('NO')
	return
if a[s-1]:
	print('YES')
	return
f = 0
for i in range(s,n):
	if a[i] and b[i]:
		f = 1
		break
if f:
	if b[s-1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')

a = input().split()
a = [int(i) for i in a]
line1 = input().split()
line2 = input().split()
if line1[0] == '0':
	print ('NO')
else:
	if line1[a[1] - 1] == '1':
		print ('YES')
	else:
		done = False
		if line2[a[1] - 1] == '1':
			for i in range(a[1], len(line1)):
				if line1[i] == '1' and line2[i] == '1':
					print('YES')
					done = True
					break
		if done == False:
			print('NO')














s,n=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
flag=0
if(arr1[0]==0):
    flag=1
elif(arr1[n-1]==0 and arr2[n-1]==0):
    flag=1
elif(arr1[n-1]==0):
    temp=0
    for j in range(n,s):
        if(arr1[j]==1 and arr2[j]==1):
            temp=1
            break
    if(temp==0):
        flag=1
        #print('YES')
if(flag==0):
    print('YES')
else:
    print('NO')


gcd = lambda a, b: gcd(b, a % b) if b else a


def main():
    n, m = list(map(int, input().split()))
    arr = [0] + list(map(int, input().split()))
    brr = [0] + list(map(int, input().split()))
    if not arr[1]:
        print("NO")
        return
    if arr[m]:
        print("YES")
        return
    if brr[m]:
        for i in range(m + 1, n + 1):
            if arr[i] and brr[i]:
                print("YES")
                return
    print("NO")
    return



main()