#include <bits/stdc++.h>
using namespace std;
string adj[6000];
int x, y, z, in[6000], finished[6000], parent[6000], n;
vector<int> cycle;
bool dfs(int v, int p) {
  in[v] = 1;
  parent[v] = p;
  for (int i = 0; i < n; i++)
    if (adj[v][i] == '1' && !finished[i]) {
      if (in[i]) {
        while (v != i) {
          cycle.push_back(v);
          v = parent[v];
        }
        cycle.push_back(i);
        return 1;
      }
      if (dfs(i, v)) return 1;
    }
  in[v] = 0;
  finished[v] = 1;
  return 0;
}
void find_(int cur, int &p) {
  int v = cycle[cur];
  int nxt = cycle[cur - 1];
  if (adj[nxt][p] == '1') {
    x = v;
    y = nxt;
    z = p;
    return;
  } else
    find_(cur - 1, p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> adj[i];
  }
  for (int i = 0; i < n; i++) {
    if (!finished[i]) {
      if (dfs(i, -1)) {
        int sz = cycle.size();
        int cur = cycle.size() - 1;
        find_(cur, cycle[cur]);
        cout << x + 1 << " " << y + 1 << " " << z + 1 << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
