#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  vector<int> firstRoute, secondRoute;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    firstRoute.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    secondRoute.push_back(a);
  }
  if (firstRoute[0] == 0) {
    cout << "NO";
    return 0;
  }
  if (firstRoute[s - 1] == 1) {
    cout << "YES";
    return 0;
  } else {
    if (secondRoute[s - 1] == 0) {
      cout << "NO";
      return 0;
    } else {
      for (int i = s; i < n; i++) {
        if (firstRoute[i] == 1 && secondRoute[i] == 1) {
          cout << "YES";
          return 0;
        }
      }
      cout << "NO";
      return 0;
    }
  }
  return 0;
}
