#include <bits/stdc++.h>
using namespace std;
long long mx = INT_MAX;
long long mi = INT_MIN;
const long long mod = 1e9 + 7;
int main() {
  vector<long long> v, vv;
  long long i, j, k, s = 0, n, x;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  for (i = 0; i < n; i++) {
    long long a;
    cin >> a;
    vv.push_back(a);
  }
  if (v[0] == 0) {
    std::cout << "NO" << std::endl;
    return 0;
  }
  if (v[x - 1] == 0 && vv[x - 1] == 0) {
    cout << "NO\n";
    return 0;
  }
  if (v[0] == 1 && v[x - 1] == 1) {
    cout << "YES";
    return 0;
  }
  for (i = x; i < n; i++) {
    if (v[i] == 1 && vv[i] == 1) {
      s = 1;
      break;
    }
  }
  if (s == 1 && vv[x - 1] == 1)
    cout << "YES\n";
  else
    cout << "NO\n";
}
