#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  --s;
  int arr[n];
  int rarr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> rarr[i];
  }
  if (arr[0] == 0 || (arr[s] == 0 && rarr[s] == 0)) {
    cout << "NO" << endl;
    return 0;
  }
  if (arr[s] == 1) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = s; i < n; ++i) {
    if (arr[i] == 1 && rarr[i] == 1) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
