#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
char m[5010][5010];
int n, u[5010], f;
bool dfs(int i) {
  int j;
  u[i] = 1;
  for (j = 0; j < n; j++)
    if (m[i][j] == '1') {
      if (!u[j] && dfs(j))
        return 1;
      else if (u[j] == 1) {
        f = j;
        return 1;
      }
    }
  u[i] = 2;
  return 0;
}
int main() {
  int i, j, k;
  for (scanf("%d", &n), i = 0; i < n; scanf("%s", m[i]), i++)
    ;
  for (i = 0; i < n; i++)
    if (!u[i] && dfs(i)) break;
  if (i == n)
    printf("-1\n");
  else
    for (i = f, j = 0; j < n; j++)
      if (j != i && m[i][j] == '1')
        for (k = 0; k < n; k++)
          if (k != i && k != j && m[j][k] == '1' && m[k][i] == '1') {
            printf("%d %d %d\n", i + 1, j + 1, k + 1);
            return 0;
          }
  return 0;
}
