#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int a[N][N], mark[N], par[N], plc[N];
vector<int> gr[N], tps, cl;
void dfs(int v) {
  mark[v] = 1;
  for (auto u : gr[v]) {
    if (!mark[u]) {
      par[u] = v;
      dfs(u);
    }
  }
  tps.push_back(v);
}
void getAns() {
  for (int i = 2; i < (int)cl.size() - 1; i++) {
    if (a[cl[i]][cl[0]]) {
      cout << cl[0] + 1 << " " << cl[i - 1] + 1 << " " << cl[i] + 1;
      exit(0);
    }
  }
  cout << cl[0] + 1 << " " << cl[cl.size() - 2] + 1 << " "
       << cl[cl.size() - 1] + 1;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      a[i][j] = c - '0';
      if (a[i][j]) gr[i].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      dfs(i);
      par[i] = i;
    }
  }
  reverse(tps.begin(), tps.end());
  for (int i = 0; i < n; i++) {
    plc[tps[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    for (auto u : gr[i]) {
      if (plc[i] > plc[u]) {
        int rn = i;
        while (rn != u) {
          cl.push_back(rn);
          rn = par[rn];
        }
        cl.push_back(u);
        reverse(cl.begin(), cl.end());
        getAns();
      }
    }
  }
  cout << -1;
  return 0;
}
