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