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