#include <bits/stdc++.h>
using namespace std;
int n, s, a[1001], b[1001], k;
int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] == 1 && a[i] == 1) k = i;
  }
  if (a[1] == 0 || (a[s] == 0 && b[s] == 0)) return cout << "NO", 0;
  if (k > s || a[s] == 1)
    cout << "YES";
  else
    cout << "NO";
}
