#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = 3.141592653589793238462;
const int nmax = 5100;
const int hash_base = 119;
const long long inf = 2e18;
int n, used[nmax], par[nmax], cst = -1, cend = -1, k, cvert[nmax];
char graph[nmax][nmax];
bool dfs(int v) {
  used[v] = 1;
  for (int i = 0; i < n; i++)
    if (i != n && graph[v][i] == '1') {
      if (used[i] == 2) continue;
      if (used[i] == 1) {
        cst = v;
        cend = i;
        return true;
      } else {
        par[i] = v;
        if (dfs(i)) return true;
      };
    };
  used[v] = 2;
  return false;
};
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", &graph[i]);
  for (int i = 0; i < n; i++)
    if (used[i] == 0)
      if (dfs(i)) break;
  for (int v = cst; v != cend; v = par[v]) cvert[k++] = v;
  cvert[k++] = cend;
  cvert[k++] = cst;
  reverse(cvert, cvert + k);
  for (int i = 0; i < k - 1; i++) {
    int v = cvert[i];
    int u = cvert[i + 1];
    for (int j = 0; j < k - 1; j++)
      if (cvert[j] != u && cvert[j] != v && graph[u][cvert[j]] == '1' &&
          graph[cvert[j]][v] == '1') {
        printf("%d %d %d\n", v + 1, u + 1, cvert[j] + 1);
        return 0;
      };
  };
  printf("-1\n");
  return 0;
}
