#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
bool first[maxn];
bool second[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n, s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    cin >> first[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> second[i];
  }
  if (s == 1) {
    cout << "YES";
    return 0;
  }
  if (!first[0]) {
    cout << "NO";
    return 0;
  }
  if (first[s - 1]) {
    cout << "YES";
    return 0;
  }
  if (!second[s - 1]) {
    cout << "NO";
    return 0;
  }
  int i = s - 1;
  bool flag = 0;
  for (i; i < n; i++) {
    flag = flag || (first[i] && second[i]);
  }
  if (flag) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
