#include <bits/stdc++.h>
using namespace std;
int n, s;
const int MAXn = 1010;
bool polje1[MAXn];
bool polje2[MAXn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> polje1[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> polje2[i];
  }
  if (!polje1[1]) {
    cout << "NO";
    return 0;
  }
  if (polje1[s]) {
    cout << "YES";
    return 0;
  }
  if (!polje2[s]) {
    cout << "NO";
    return 0;
  }
  for (int i = s + 1; i <= n; i++) {
    if (polje1[i] && polje2[i]) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
