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