#include <bits/stdc++.h>
using namespace std;
int grid[1001][1001];
int visited[1001][1001];
int a[1001];
int b[1001];
int s, n;
bool t = 0;
void dfs(int x) {
  if (x == s) {
    t = 1;
    return;
  }
  for (int j = 1; j <= n; j++) {
    if (visited[x][j] == 0 && grid[x][j] == 1) {
      visited[x][j] = 1;
      dfs(j);
    }
  }
}
int main() {
  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 && b[i])
        if (b[j] == 1) {
          grid[i][j] = 1;
        }
      if (i < j && a[i])
        if (a[j] == 1) {
          grid[i][j] = 1;
        }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) visited[i][j] = 0;
  dfs(1);
  if (t)
    cout << "YES";
  else {
    cout << "NO";
  }
  return 0;
}
