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