#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
int a[MAXN];
vector<vector<int> > g;
int n, m, k, doneN;
int done[MAXN];
int v[MAXN];
char c;
queue<int> q = queue<int>();
void f() {
  int x = q.front();
  q.pop();
  for (int i = 0; i < g[x].size(); ++i) {
    int to = g[x][i];
    v[to]++;
    if (!done[to] && v[to] == a[to]) {
      q.push(to);
      done[to] = 1;
    }
  }
}
int main() {
  cin >> n;
  g = vector<vector<int> >(n, vector<int>());
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> c;
      if (c - '0') {
        g[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) {
      if (!done[i]) {
        q.push(i);
        done[i] = 1;
      }
    }
  }
  while (!q.empty()) {
    f();
  }
  bool fl = true;
  for (int i = 0; i < n; ++i) {
    if (v[i] == a[i]) {
      fl = false;
      break;
    }
    if (done[i]) {
      doneN++;
    }
  }
  if (fl) {
    cout << doneN << "\n";
    for (int i = 0; i < n; ++i) {
      if (done[i]) {
        cout << (i + 1) << " ";
      }
    }
  } else {
    cout << -1;
  }
  return 0;
}
