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