#include <bits/stdc++.h>
const int maxn = 100010;
const int inf = ~(1u << 31u);
const long long linf = ~(1llu << 63u);
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, s;
  bool ok = false;
  cin >> n >> s;
  vector<int> a(n), b(n);
  for (auto &x : a) cin >> x;
  for (auto &x : b) cin >> x;
  for (int i = s; i < n; i++)
    if (a[i] == 1 && b[i] == 1) ok = true;
  if (a[0] == 1 && (a[s - 1] == 1 || (b[s - 1] == 1 && ok)))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
