#include <bits/stdc++.h>
using namespace std;
int n;
char second[5100][5100];
int cycle[10000], cn;
int color[5100], cc, num[5100];
void print(int l, int r) {
  if (r - l == 2) {
    for (int i = l; i <= r; ++i) printf("%d ", cycle[i] + 1);
    exit(0);
  }
  int u = cycle[l];
  int v = cycle[l + 2];
  if (second[v][u] == '1')
    print(l, l + 2);
  else {
    cycle[r + 1] = cycle[l];
    print(l + 2, r + 1);
  }
}
void dfs(int u) {
  color[u] = cc;
  cycle[++cn] = u;
  num[u] = cn;
  for (int i = 0; i < n; ++i)
    if (second[u][i] == '1') {
      if (color[i] == cc) {
        print(num[i], cn);
      } else if (!color[i])
        dfs(i);
    }
  color[u] = -1;
  --cn;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; ++i) gets(second[i]);
  for (int i = 0; i < n; ++i)
    if (!color[i]) {
      ++cc;
      dfs(i);
    }
  puts("-1");
}
