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