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