#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool ans = 0;
  cin >> n >> m;
  vector<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) {
    ans = 0;
  } else {
    if (a[m - 1] == 1) {
      ans = 1;
    } else {
      if (b[m - 1] == 1) {
        for (int i = m - 1; i < n; i++) {
          if (a[i] == 1 && b[i] == 1) {
            ans = 1;
            break;
          }
        }
      }
    }
  }
  if (ans == 1)
    cout << "YES";
  else
    cout << "NO";
}
