#include <bits/stdc++.h>
using namespace std;
int main() {
  int Arr1[2000];
  int Arr2[2000];
  int N, S;
  cin >> N >> S;
  for (int i = 1; i <= N; i++) {
    cin >> Arr1[i];
  }
  for (int i = 1; i <= N; i++) {
    cin >> Arr2[i];
  }
  if (!Arr1[1])
    cout << "NO";
  else {
    bool Yes = 0;
    for (int i = 1; i <= N; i++) {
      if (Arr1[i] && i == S) {
        Yes = 1;
        break;
      }
    }
    if (!Yes) {
      for (int i = 1; i <= N; i++) {
        if (Arr1[i] && i >= S && Arr2[i]) {
          if (Arr2[S]) {
            Yes = 1;
            break;
          }
        }
      }
      if (Yes)
        cout << "YES\n";
      else
        cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}
