#include <bits/stdc++.h>
using namespace std;
void mDG(vector<int> arr[], int v) {
  int u, lc = -1;
  for (int i = 0; i < v; i++) {
    cin >> u;
    if (u) {
      if (lc == -1) lc = i;
      arr[lc].push_back(i);
      lc = i;
    }
  }
  stack<int> st;
  for (int i = 0; i < v; i++) {
    cin >> u;
    st.push(u);
  }
  lc = -1;
  while (!st.empty()) {
    u = st.top();
    if (u) {
      if (lc == -1) lc = st.size() - 1;
      arr[lc].push_back(st.size() - 1);
      lc = st.size() - 1;
    }
    st.pop();
  }
}
void p(vector<int> arr[], int v) {
  for (int i = 0; i < v; i++) {
    for (int v : arr[i])
      if (v != i) cout << v << " ";
    cout << endl;
  }
}
bool solve(vector<int> arr[], int n, int s) {
  queue<int> q;
  q.push(0);
  int visited[n];
  fill(visited, visited + n, -1);
  visited[0] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : arr[u]) {
      if (visited[v] == -1) {
        visited[v] = visited[u] + 1;
        q.push(v);
      }
    }
  }
  return visited[s - 1] != -1;
}
int main() {
  int n, s;
  cin >> n >> s;
  vector<int> arr[n];
  mDG(arr, n);
  if (solve(arr, n, s))
    cout << "YES";
  else
    cout << "NO";
}
