#include <bits/stdc++.h>
char graph[5010][5010];
bool vis[5010];
int n;
bool dfs(int now, int pre) {
  vis[now] = true;
  for (int v = 0; v < n; v++)
    if (graph[now][v] == '1') {
      if (vis[v]) {
        if (pre != -1 && graph[v][pre] == '1') {
          printf("%d %d %d\n", now + 1, v + 1, pre + 1);
          return true;
        }
      } else {
        if (dfs(v, now)) return true;
      }
    }
  return false;
}
int main() {
  scanf("%d", &n);
  gets(graph[0]);
  for (int i = 0; i < n; i++) gets(graph[i]);
  memset(vis, false, sizeof(vis));
  bool flag = true;
  for (int i = 0; i < n && flag; i++)
    if (!vis[i])
      if (dfs(i, -1)) flag = false;
  if (flag) printf("-1\n");
  return 0;
}
