#include <bits/stdc++.h>
#pragma GCC optimize
const long long INF = std::numeric_limits<long long>::max() - 1ll;
int main() {
  std::iostream::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  long long n = 0ll, s = 0ll;
  std::cin >> n >> s;
  std::vector<long long> a((unsigned long long)n), b((unsigned long long)n);
  for (long long i = 0ll; i < n; ++i) {
    std::cin >> a[i];
  }
  for (long long i = 0ll; i < n; ++i) {
    std::cin >> b[i];
  }
  if ((a[s - 1ll] == b[s - 1ll] && a[s - 1ll] == 0ll) || a[0] == 0ll) {
    std::cout << "NO";
    exit(0);
  }
  if (a[s - 1ll] == 1ll) {
    std::cout << "YES";
    exit(0);
  }
  long long cnt = 0ll;
  for (long long i = s; i < n; ++i) {
    if (a[i] == b[i] && a[i] == 1ll) ++cnt;
  }
  if (b[s - 1ll] == 1ll && cnt > 0ll) {
    std::cout << "YES";
    exit(0);
  }
  std::cout << "NO";
  exit(0);
}
