#include <bits/stdc++.h>
using namespace std;
const int N = 101;
vector<int> from[N], to[N], ans;
set<pair<int, int> > st;
int ar[N];
int n;
bool used[N];
int getzero() {
  for (int i = 0; i < n; ++i) {
    if (!ar[i]) return i;
  }
  return -1;
}
bool dfs(int ind) {
  for (auto &x : to[ind]) {
    if (used[x]) continue;
    used[x] = true;
    for (auto &y : from[x]) --ar[y];
    ans.push_back(x);
    int tmp;
    if ((tmp = getzero()) == -1) {
      cout << ans.size() << endl;
      for (auto &z : ans) cout << z + 1 << " ";
      return true;
    }
    if (dfs(tmp)) return true;
    ans.pop_back();
    for (auto &y : from[x]) ++ar[y];
    used[x] = false;
  }
  return false;
}
int main() {
  char c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> c;
      if (c == '1') {
        to[j].push_back(i);
        from[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < n; ++i) cin >> ar[i];
  int ind = getzero();
  memset(used, false, N);
  if (ind == -1) {
    cout << 0;
    return 0;
  }
  if (!dfs(ind)) {
    cout << -1;
    return 0;
  }
  return 0;
}
