#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int a[maxn], b[maxn];
int main() {
  cin >> n >> m;
  m--;
  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";
    return 0;
  }
  if (b[m] == 0 && a[m] == 0) {
    cout << "NO";
    return 0;
  }
  if (a[m] != 0) {
    cout << "YES";
    return 0;
  }
  for (int i = m; i < n; i++) {
    if (b[i] == 1 && a[i] == 1) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
