#include <bits/stdc++.h>
using namespace std;
int n, vis[5009], d[5009][5009];
vector<int> e;
vector<vector<int> > g;
char s[5009];
void dfs(int v, int pr = -1) {
  int i;
  vis[v] = 1;
  for (auto u : g[v]) {
    if (d[u][pr] == 1 && pr != -1) {
      cout << u << " " << pr << " " << v;
      exit(0);
    }
    if (!vis[u]) dfs(u, v);
  }
}
int main() {
  int i, j;
  scanf("%d", &n);
  g.resize(n + 1);
  ;
  for (i = (1); i <= (n); i++) {
    scanf("%s", s);
    ;
    for (j = (0); j <= (n - 1); j++)
      if (s[j] == '1') {
        g[i].push_back(j + 1);
        d[i][j + 1] = 1;
      }
  };
  for (i = (1); i <= (n); i++) {
    if (!vis[i]) dfs(i);
  }
  cout << "-1";
}
