#include <bits/stdc++.h>
using namespace std;
void dfs(int start, vector<bool>& visited, const vector<vector<int>>& g) {
  visited[start] = true;
  for (int i = 0; i < g.size(); i++)
    if (!visited[i] && g[start][i] == 1) dfs(i, visited, g);
}
int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  vector<vector<int>> g(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1)
      for (int j = i + 1; j <= n; j++)
        if (a[j] == 1) g[i][j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (b[i] == 1)
      for (int j = i + 1; j <= n; j++)
        if (b[j] == 1) g[j][i] = 1;
  }
  vector<bool> visited(n + 1, false);
  dfs(1, visited, g);
  if (visited[s])
    cout << "YES";
  else
    cout << "NO";
}
