#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, s, h, temp = 0;
  cin >> n >> s;
  long track1[n];
  long track2[n];
  for (long t = 0; t < n; t++) {
    cin >> h;
    track1[t] = h;
  }
  for (long y = 0; y < n; y++) {
    cin >> h;
    track2[y] = h;
  }
  if (s == 1) {
    cout << "YES";
  } else {
    if (track1[0] == 0 && s != 1) {
      cout << "NO";
    } else {
      if (track1[s - 1] == 1) {
        cout << "YES";
      } else {
        for (long i = n - 1; i > 1; i--) {
          if (track1[i] == 1 && i >= s && track2[i] == 1) {
            temp++;
            i = -1;
          }
        }
        if (track2[s - 1] == 1) {
          temp++;
        }
        if (temp == 2) {
          cout << "YES";
        } else {
          cout << "NO";
        }
      }
    }
  }
  return 0;
}
