#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, a, b, c;
bool dist[N][N], vis[N];
char mapp[N][N];
bool dfs(int st, int fa) {
  vis[st] = 1;
  for (int i = 1; i <= n; i++) {
    if (!dist[st][i]) continue;
    if (dist[i][fa] && fa) {
      a = fa, b = st, c = i;
      return 1;
    }
    if (!vis[i])
      if (dfs(i, st)) return 1;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", mapp[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (mapp[i][j] == '1') dist[i + 1][j + 1] = 1;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    if (dfs(i, 0)) {
      printf("%d %d %d", a, b, c);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
