#include <bits/stdc++.h>
using namespace std;
int a[1003], b[1003];
int main() {
  int n, s;
  scanf("%d %d", &n, &s);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  if (a[0] == 0 || (a[s - 1] == 0 && b[s - 1] == 0)) return printf("NO"), 0;
  if (a[s - 1] == 1) return printf("YES"), 0;
  for (int i = s; i < n; i++) {
    if (a[i] == 1 && b[i] == 1) {
      return printf("YES"), 0;
    }
  }
  printf("NO");
  return 0;
}
