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