#include <bits/stdc++.h>
int main() {
  int n, s, *forward, *back, flag = 1;
  scanf("%d%d", &n, &s);
  getchar();
  forward = (int*)malloc(n * sizeof(int));
  back = (int*)malloc(n * sizeof(int));
  for (int i = 0; i <= n - 1; i++) {
    scanf("%d", &forward[i]);
    getchar();
  }
  for (int i = 0; i <= n - 1; i++) {
    scanf("%d", &back[i]);
    getchar();
  }
  if (forward[0] != 1)
    printf("NO\n");
  else if (forward[s - 1] == 1)
    printf("YES\n");
  else {
    if (back[s - 1] != 1) {
      flag = 0;
    } else {
      for (int i = s - 1; i <= n - 1; i++) {
        if (forward[i] == 1 && back[i] == 1) {
          flag = 1;
          break;
        } else
          flag = 0;
      }
    }
    if (flag == 1)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
