#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
int n, low[MAXN], dfn[MAXN], tot, stk[MAXN], top, tmp[MAXN], t;
bool vis[MAXN];
char G[MAXN][MAXN];
void dfs(int x) {
  vis[x] = 1;
  dfn[x] = low[x] = ++tot;
  stk[++top] = x;
  for (int i = 1; i <= n; i++)
    if (G[x][i] == '1') {
      if (!dfn[i])
        dfs(i), low[x] = min(low[x], low[i]);
      else if (vis[i])
        low[x] = min(low[x], dfn[i]);
    }
  if (low[x] == dfn[x]) {
    int y = 0;
    t = 0;
    do {
      y = stk[top--];
      tmp[++t] = y;
      vis[y] = 0;
    } while (y != x);
    for (int i = 1; i < t; i++)
      for (int j = 1; j < t; j++)
        if (G[x][tmp[i]] == '1' && G[tmp[i]][tmp[j]] == '1' &&
            G[tmp[j]][x] == '1') {
          printf("%d %d %d\n", x, tmp[i], tmp[j]);
          exit(0);
        }
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", G[i] + 1);
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  printf("-1\n");
  return 0;
}
