#include <bits/stdc++.h>
using namespace std;
bool mas1[1010], mas2[1020];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  std::ios::sync_with_stdio(false);
  int n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> mas1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> mas2[i];
  }
  s--;
  if (mas1[0] == 0) {
    cout << "NO";
    return 0;
  }
  if (mas1[s] != 1) {
    if (mas2[s] == 1) {
      for (int i = s; i < n; i++) {
        if (mas1[i] && mas2[i]) {
          cout << "YES";
          return 0;
        }
      }
      cout << "NO" << endl;
    } else {
      cout << "NO";
    }
  } else {
    cout << "YES";
    return 0;
  }
  return 0;
}
