#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  vector<int> up(n), dwn(n);
  for (int i = 0; i < n; ++i) scanf("%d", &up[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &dwn[i]);
  if (!up[0] || (up[0] && !up[s - 1] && !dwn[s - 1]))
    puts("NO");
  else if (up[0] && up[s - 1])
    puts("YES");
  else {
    for (int i = s; i < n; ++i) {
      if (up[i] && dwn[i]) {
        puts("YES");
        return 0;
      }
    }
    puts("NO");
  }
  return 0;
}
