#include <bits/stdc++.h>
using namespace std;
int main() {
  int s, n;
  cin >> n >> s;
  int arr[2][n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[0][i];
  for (int i = 1; i <= n; i++) cin >> arr[1][i];
  int flag = 0;
  if (arr[0][1] == 0)
    flag = 0;
  else if (arr[0][s] == 0 && arr[1][s] == 0)
    flag = 0;
  else if (arr[0][s] == 1)
    flag = 1;
  else if (arr[0][s] == 0 && arr[1][s] == 1) {
    for (int i = s + 1; i <= n; i++)
      if (arr[0][i] == 1 && arr[1][i] == 1) flag = 1;
  }
  if (flag == 0)
    cout << "NO";
  else
    cout << "YES";
}
