#include <bits/stdc++.h>
using namespace std;
char _;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long fpow(long long b, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long t = fpow(b, exp / 2, mod);
  if (exp & 1) return t * t % mod * b % mod;
  return t * t % mod;
}
int num_stations, target, arr1[1005], arr2[1005];
int main() {
  scanf("%d %d", &num_stations, &target);
  if (target == 1) {
    printf("YES\n");
    return 0;
  }
  for (int i = 1; i <= num_stations; i++) scanf(" %d", &arr1[i]);
  if (arr1[1] && arr1[target]) {
    printf("YES\n");
    return 0;
  }
  for (int i = 1; i <= num_stations; i++) scanf(" %d", &arr2[i]);
  if (!arr1[1]) {
    printf("NO\n");
    return 0;
  }
  for (int i = target; i <= num_stations; i++) {
    if (arr2[target] && arr1[i] && arr2[i]) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
}
