#include <bits/stdc++.h>
using namespace std;
const int size = 5 * 1000 + 10;
char way[size][size];
int len, n, col[size], st[size];
bool flag;
void dfs(int v) {
  int i;
  if (flag) return;
  col[v] = 1;
  st[len++] = v;
  for (i = 0; i < n; i++)
    if (way[v][i] == '1' && col[i] == 1) {
      flag = true;
      printf("%d %d %d\n", i + 1, st[len - 2] + 1, v + 1);
      return;
    }
  for (i = 0; i < n; i++)
    if (way[v][i] == '1' && col[i] == 0) {
      dfs(i);
      if (flag) return;
    }
  len--;
  col[v] = 2;
  return;
}
int main() {
  int i, j;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) scanf("%s", way[i]);
  flag = false;
  len = 0;
  for (i = 0; i < n; i++)
    if (col[i] == 0) dfs(i);
  if (!flag) printf("-1\n");
  return 0;
}
