#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  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" << endl;
  else {
    int reach[1001] = {0};
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        reach[i] = 1;
        if (b[i] == 1) {
          for (int j = 0; j <= i; j++) {
            if (b[j] == 1) reach[j] = 1;
          }
        }
      }
    }
    if (reach[k - 1] == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
