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