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