#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
char G[MAXN][MAXN];
int n;
bool vis[MAXN];
void dfs(int x, int p) {
  vis[x] = 1;
  for (int i = 1; i <= n; i++)
    if (G[x][i] == '1') {
      if (G[i][p] == '1') {
        printf("%d %d %d\n", p, x, i);
        exit(0);
      }
      if (!vis[i]) dfs(i, x);
    }
  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 (!vis[i]) dfs(i, 0);
  printf("-1\n");
  return 0;
}
