#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void c_p_c() {}
void parray(int a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
int no = 1, n1;
bool check(int a, int b, int n) {
  bool b1 = false, b2 = false, b3 = false;
  if (a % b == 0) b1 = true;
  if ((a * b) > n) b2 = true;
  if ((a / b) < n) b3 = true;
  return (b1 and b2 and b3);
}
int main() {
  int i, m, k, n;
  long long int sum = 0;
  c_p_c();
  cin >> n >> m;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) cin >> b[i];
  if (a[0] == 0) {
    cout << "NO"
         << "\n";
    return 0;
  } else if (a[m - 1] == 1) {
    cout << "YES"
         << "\n";
    return 0;
  } else if (b[m - 1] == 0) {
    cout << "NO"
         << "\n";
    return 0;
  } else {
    for (int i = m - 1; i < n; ++i) {
      if (a[i] == b[i] and a[i] == 1) {
        cout << "YES"
             << "\n";
        return 0;
      }
    }
    cout << "NO"
         << "\n";
  }
}
