#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  bool vuelta = false;
  int metro[n][2];
  for (int i = 0; i < n; i++) {
    cin >> metro[i][0];
  }
  for (int i = 0; i < n; i++) {
    cin >> metro[i][1];
  }
  for (int i = s; i < n; i++) {
    if (metro[i][0] == 1 && metro[i][1] == 1) {
      vuelta = true;
    }
  }
  if (metro[0][0] == 0) {
    cout << "NO";
  } else {
    if (metro[s - 1][0] == 0) {
      if (vuelta) {
        if (metro[s - 1][1] == 1) {
          cout << "YES";
        } else {
          cout << "NO";
        }
      } else {
        cout << "NO";
      }
    } else {
      cout << "YES";
    }
  }
}
