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