#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
const long long inf = 1000 * 1000 * 1000 + 7;
const long long INF = inf * inf;
const long long MOD = inf;
const long long N = 3e5 + 10, base = 1 << 18;
long long p[N];
long long d[N];
long long moze[N];
long long n, s;
void solve() {
  cin >> n >> s;
  for (long long i = (1); i <= (n); i++) cin >> p[i];
  for (long long i = (1); i <= (n); i++) cin >> d[i];
  if (!p[1]) {
    cout << "NO\n";
    return;
  }
  if (p[s]) {
    cout << "YES\n";
    return;
  }
  long long najdalej = 0;
  for (long long i = (1); i <= (n); i++)
    if (p[i] && d[i]) najdalej = i;
  if (najdalej >= s && d[s])
    cout << "YES\n";
  else
    cout << "NO\n";
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cout << setprecision(9) << fixed;
  cerr << setprecision(6) << fixed;
  long long test = 1;
  while (test--) {
    solve();
  }
}
