#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, i;
  cin >> n >> k;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  ;
  for (long long i = 0; i < n; i++) cin >> b[i];
  ;
  if (a[0] == 0) {
    cout << "NO";
    return 0;
  }
  k--;
  long long val = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == 1 && i == k) {
      cout << "YES";
      return 0;
    }
    if (a[i] == 1 && b[i] == 1) val = i;
  }
  for (i = val; i >= 0; i--) {
    if (b[i] == 1 && i == k) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
}
