#include <bits/stdc++.h>
using namespace std;
bool f(int n, int** adj, int* visited, int v1, int v2) {
  if (adj[v1][v2] == 1) {
    return true;
  }
  for (int i = 0; i < n; i++) {
    if (visited[i] != 1 && adj[v1][i] == 1) {
      visited[i] = 1;
      if (f(n, adj, visited, i, v2)) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  int n, s;
  cin >> n >> s;
  int** adj = new int*[n];
  for (int i = 0; i < n; i++) {
    adj[i] = new int[n]{0};
  }
  int* visited = new int[n]{0};
  int* a = new int[n];
  int* b = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] == 1 && a[j] == 1) {
        adj[i][j] = 1;
        break;
      }
    }
  }
  for (int i = n - 1; i >= 1; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if (b[i] == 1 && b[j] == 1) {
        adj[i][j] = 1;
        break;
      }
    }
  }
  bool ans = f(n, adj, visited, 0, s - 1);
  cout << (ans == 1 ? "YES" : "NO");
  for (int i = 0; i < n; i++) {
    delete[] adj[i];
  }
  delete[] adj;
  delete[] visited;
  delete[] a;
  delete[] b;
  return 0;
}
