#include <bits/stdc++.h>
int n;
bool mark[5100];
bool g[5100][5100];
char cmd[5100];
void DFS(int rt, int pre) {
  mark[rt] = 1;
  for (int i = 1; i <= n; ++i)
    if (g[rt][i]) {
      if (!mark[i])
        DFS(i, rt);
      else if (g[i][pre]) {
        printf("%d %d %d\n", pre, rt, i);
        exit(0);
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", cmd + 1);
    for (int j = 1; j <= n; ++j)
      if (cmd[j] == '1') g[i][j] = 1;
  }
  for (int i = 1; i <= n; ++i)
    if (!mark[i]) DFS(i, 0);
  puts("-1");
  return 0;
}
