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