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