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