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