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