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