#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000];
bool visited[1000];
bool possible = false;
int n, m;
void dfs(int s) {
  if (visited[s]) return;
  if (s == m) {
    possible = true;
    return;
  }
  visited[s] = true;
  int j;
  for (j = 0; j < adj[s].size(); j++) {
    dfs(adj[s][j]);
  }
}
using namespace std;
int main() {
  int i, k;
  cin >> n >> m;
  int first[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> first[i];
  }
  int second[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> second[i];
  }
  for (i = 1; i <= n; i++) {
    if (first[i]) {
      for (k = i + 1; k <= n; k++) {
        if (first[k]) {
          adj[i].push_back(k);
        }
      }
    }
  }
  for (i = n; i > 0; i--) {
    if (second[i]) {
      for (k = i - 1; k > 0; k--) {
        if (second[k]) {
          adj[i].push_back(k);
        }
      }
    }
  }
  dfs(1);
  if (possible)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
