#include <bits/stdc++.h>
using namespace std;
int n, s;
vector<int> v[5];
bool check1, check2, check3, now;
int pos;
int main() {
  cin >> n >> s;
  int a;
  now = false;
  check2 = true;
  check1 = true;
  check3 = true;
  for (int e = 0; e < 2; e++) {
    for (int w = 0; w < n; w++) {
      cin >> a;
      v[e].push_back(a);
    }
  }
  if (v[0][0] == 0) {
    cout << "NO" << endl;
    return 0;
  }
  if (v[0][s - 1] == 0 && v[1][s - 1] == 0) {
    cout << "NO" << endl;
    return 0;
  }
  if (v[0][s - 1] == 1) {
    cout << "YES" << endl;
    return 0;
  }
  pos = 1;
  for (int q = 1; q < v[0].size(); q++) {
    if (v[0][q] == 1 && v[1][q] == 1 && q >= s) {
      if (v[1][q] == 1) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  if (pos == s) {
    cout << "YES" << endl;
    return 0;
  } else if (pos < s) {
    cout << "NO" << endl;
  }
}
