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