def backward_possible(backward, s):
    if backward[s] == 0:
        return False

    count = 0
    for i, j in zip(forward[s+1:], backward[s+1:]):
        if i == 1 and j == 1:
            break
        else:
            count += 1
    if count == len(forward[s+1:]):
        return False
    else:
        return True


if __name__ == "__main__":
    n, s = list(map(int, input().split()))
    forward = list(map(int, input().split()))
    backward = list(map(int, input().split()))
    


    s -= 1
    if forward[0] == 0 or forward[s] + backward[s] == 0:
        print('NO')
        exit()
    
    if forward[s]:
        print('YES')
        exit()
    elif backward_possible(backward, s):
        print('YES')
    else:
        print('NO')
        
        
