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