#include <bits/stdc++.h>
using namespace std;
bool mk[1000];
int main() {
  int n, k;
  cin >> n >> k;
  int x;
  cin >> x;
  int r = 0, e = 1;
  if (x == 0) e = 0;
  if (k == 1 && x == 1) r = 1;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    if (i == k)
      if (x == 1) r = 1;
    if (x == 1) mk[i] = true;
  }
  int p = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (i == k && x == 1) p = 1;
    if (i > k && x == 1 && p == 1)
      if (mk[i] == true) r = 1;
  }
  if (e == 0) {
    cout << "NO";
    return 0;
  }
  if (r == 1) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
