#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, s;
int o1[maxn];
int o2[maxn];
int main() {
  cin >> n >> s;
  for (int i = 1; i < n + 1; i++) {
    cin >> o1[i];
  }
  for (int i = 1; i < n + 1; i++) {
    cin >> o2[i];
  }
  if (o1[1] == 0) {
    puts("NO");
    return 0;
  }
  bool flag = false;
  for (int i = s; i <= n; i++) {
    if (o1[i] && o2[i]) {
      flag = true;
      break;
    }
  }
  if (o1[s] || flag && o2[s]) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
}
