#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  long long n, p = 0, q = 0, l = 0, i, flag = 0, k, m, t, j, r = 0, curr = 0, d;
  cin >> n >> m;
  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;
  }
  if (a[0] != 0) {
    if (a[m - 1] != 0) {
      cout << "YES";
      return 0;
    }
  }
  if (a[m - 1] == 0) {
    for (long long i = m; i < n; i++) {
      if (a[i] == 1 && b[i] == 1) {
        if (b[m - 1] == 1) {
          flag = 1;
          break;
        }
      }
    }
  }
  if (flag == 1) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
