#include <bits/stdc++.h>
using namespace std;
int n, vis[5000];
char a[5000][5005];
void dfs(int node, int prev) {
  vis[node] = 1;
  for (int i = 0; i < n; i++)
    if (a[node][i] == '1') {
      if (!vis[i])
        dfs(i, node);
      else if (a[i][prev] == '1' && a[prev][node] == '1')
        exit(!printf("%d %d %d\n", node + 1, i + 1, prev + 1));
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  for (int i = 0; i < n; i++)
    if (!vis[i]) dfs(i, -1);
  printf("-1");
}
