#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i, s, c = 0;
  cin >> n >> s;
  int a[n + 1], b[n + 1];
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  if (a[1] == 0)
    cout << "NO";
  else if (a[1] == 1) {
    if (a[s] == 1)
      cout << "YES";
    else if (a[s] == 0) {
      for (i = s; i <= n; i++) {
        if (a[i] == 1 && b[i] == 1) {
          c++;
          break;
        }
      }
      if (c == 1) {
        if (b[s] == 1)
          cout << "YES";
        else if (b[s] == 0)
          cout << "NO";
      } else if (c == 0)
        cout << "NO";
    }
  }
  return 0;
}
