#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 5;
int a[1005]{0}, b[1005]{0}, visited[1005]{0};
int mat[1005][1005]{0};
vector<int> g[1005];
int n, s;
int dfs(int v, int s) {
  visited[v] = true;
  if (v == s) return 1;
  for (auto e : g[v]) {
    if (!visited[e])
      if (dfs(e, s) == 1) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i != j) mat[i][j] = 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i] != 1) {
      for (int j = 1; j < i; ++j) mat[j][i] = 0;
      for (int j = i + 1; j <= n; ++j) mat[i][j] = 0;
    }
    if (b[i] != 1) {
      for (int j = i + 1; j <= n; ++j) mat[j][i] = 0;
      for (int j = 1; j <= i - 1; ++j) mat[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (mat[i][j]) g[i].push_back(j);
    }
  }
  int ans = dfs(1, s);
  if (ans == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
