#include <bits/stdc++.h>
typedef struct pair {
  int st, nd;
} pair;
int const N = 5001;
int i, j, k, s, n, m, kArr[N], yArr[N], hash[N], hashNode[N];
int graph[N][N];
char str[N + 1];
void dfs(int currentNode, int preNode) {
  int i, j;
  hash[currentNode] = true;
  for (i = 1; i <= n; i++) {
    if (!graph[currentNode][i]) continue;
    if (hash[i] && !hashNode[i] && graph[currentNode][i]) {
      printf("%d %d %d", preNode, currentNode, i);
      exit(NULL);
    }
    if (!hash[i] && graph[currentNode][i]) {
      dfs(i, currentNode);
    }
  }
  hashNode[currentNode] = true;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", str + 1);
    for (j = 1; j <= n; j++) {
      if (str[j] == '1') {
        graph[i][j] = true;
      }
    }
  }
  for (i = 1; i <= n; i++) {
    if (!hash[i]) {
      dfs(i, -1);
    }
  }
  puts("-1");
  return 0;
}
