#include <bits/stdc++.h>
using namespace std;
long long max3(long long x, long long y, long long z) {
  return max(max(x, y), z);
}
long long min3(long long x, long long y, long long z) {
  return min(min(x, y), z);
}
int const M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, s;
  cin >> n >> s;
  long long a[n + 1], b[n + 1];
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  for (long long i = 1; i < n + 1; i++) cin >> b[i];
  if (a[1] == 0) {
    cout << "NO";
    return 0;
  }
  if (b[s] == 0 && a[s] == 0) {
    cout << "NO";
    return 0;
  }
  if (a[s] == 1) {
    cout << "YES";
    return 0;
  }
  for (long long i = s + 1; i < n + 1; i++) {
    if (a[i] == b[i] && a[i] == 1) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
