#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, cnt = 0;
  cin >> n >> s;
  int a[n + 1], b[n + 1];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  if (a[0] != 1)
    cout << "NO";
  else if (a[0] == 1 && a[s - 1] == 1)
    cout << "YES";
  else if (a[s - 1] != 1 && b[s - 1] == 1) {
    for (int j = s; j < n; j++) {
      if (a[j] == 1 && b[j] == 1) {
        cnt++;
        break;
      }
    }
    if (cnt != 0)
      cout << "YES";
    else
      cout << "NO";
  } else
    cout << "NO";
}
