#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  bool flag = false;
  cin >> n >> s;
  int fr[n + 1], ba[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> fr[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> ba[i];
  }
  if (fr[1] == 0)
    cout << "NO";
  else {
    if (fr[s] == 1)
      cout << "YES";
    else {
      if (ba[s] == 0)
        cout << "NO";
      else {
        for (int j = s + 1; j <= n; j++) {
          if (fr[j] == 1 && ba[j] == 1) {
            cout << "YES";
            flag = true;
            break;
          }
        }
        if (!flag) cout << "NO";
      }
    }
  }
  return 0;
}
