#include <bits/stdc++.h>
using namespace std;
void dark_knight() {
  long long n, s;
  cin >> n >> s;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long flag = 0, mean = 0;
  for (long long j = s; j < n; j++) {
    if (a[j] == 1 && b[j] == 1) flag++;
  }
  if (a[0] == 0)
    cout << "NO\n";
  else if (b[s - 1] == 0 && a[s - 1] == 0)
    cout << "NO\n";
  else if (a[s - 1] == 1)
    cout << "YES\n";
  else if (b[s - 1] == 1 && flag > 0)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    dark_knight();
  }
  return 0;
}
