#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (5000 + 500);
char str[MAX_N][MAX_N];
int N, found, vis[MAX_N];
vector<int> g[MAX_N];
vector<int> ans;
void dfs(int u, int father) {
  vis[u] = 1;
  for (int v = (0); v < (N); ++v)
    if (str[u][v] == '1') {
      if (!vis[v])
        dfs(v, u);
      else if (str[v][father] == '1') {
        found = 1;
        printf("%d %d %d\n", father + 1, u + 1, v + 1);
      }
      if (found) return;
    }
}
int main() {
  while (cin >> N) {
    ans.clear();
    for (int i = (1); i <= (N); ++i) g[i].clear();
    for (int i = (0); i < (N); ++i) scanf("%s", str[i]);
    memset(vis, 0, sizeof(vis));
    found = 0;
    for (int i = (0); i < (N); ++i)
      if (!vis[i] && !found) dfs(i, i);
    if (!found) {
      puts("-1");
    }
  }
  return 0;
}
