#include <bits/stdc++.h>
using namespace std;
int main() {
  int s, n;
  cin >> s >> n;
  vector<int> go(1001, 0);
  vector<int> in(1001, 0);
  for (int a = 1; a <= s; a++) {
    cin >> go[a];
  }
  for (int a = 1; a <= s; a++) {
    cin >> in[a];
  }
  if (go[1] == 0 || (go[n] == 0 && in[n] == 0)) {
    cout << "NO" << endl;
  } else if (go[n] == 1) {
    cout << "YES" << endl;
  } else {
    int ind = -1;
    for (int a = n + 1; a <= s; a++) {
      if (go[a] == 1 && in[a] == 1) {
        ind = a;
        break;
      }
    }
    if (ind == -1) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
  return 0;
}
