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