#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[100010], b[100010];
  int m, n, k = 1, p, l, i;
  cin >> m >> n;
  p = m;
  l = n;
  for (i = 1; i <= m; i++) cin >> arr[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  if (arr[1] == 1 && arr[n] == 1) {
    cout << "YES" << endl;
    return 0;
  } else if (arr[1] == 1 && arr[n] == 0) {
    for (i = n; i <= m; i++) {
      if (arr[i] == 1 && b[i] == 1 && b[n] == 1) {
        cout << "YES" << endl;
        return 0;
      } else
        k = 0;
    }
    if (k == 0) {
      cout << "NO" << endl;
      return 0;
    }
  } else {
    cout << "NO" << endl;
    return 0;
  }
}
