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