#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007, N = 2005;
bool a[N], b[N], ok[N];
int mx = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, s;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  if (a[1])
    for (int i = 1; i <= n; i++) {
      if (a[i]) ok[i] = 1;
      if (a[i] && b[i]) mx = max(mx, i);
    }
  for (int i = mx; i >= 1; i--) {
    if (b[i]) ok[i] = 1;
  }
  if (ok[s])
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
