#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int src, dst;
  int weight;
  Edge(int src, int dst, int weight = 1) : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}
bool visit(const vector<vector<Edge> > &g, int v, vector<int> &order,
           vector<int> &color, vector<int> &next) {
  color[v] = 1;
  for (__typeof((g[v]).begin()) e = (g[v]).begin(); e != (g[v]).end(); ++e) {
    if (color[e->dst] == 2) continue;
    if (color[e->dst] == 1) {
      order.clear();
      int t = e->dst;
      while (1) {
        order.push_back(t);
        if (t == v) break;
        t = next[t];
      }
      return false;
    }
    next[v] = e->dst;
    if (!visit(g, e->dst, order, color, next)) return false;
    next[v] = -1;
  }
  order.push_back(v);
  color[v] = 2;
  return true;
}
bool topologicalSort(const vector<vector<Edge> > &g, vector<int> &order) {
  int n = g.size();
  vector<int> color(n), next(n, -1);
  for (int u = 0; u < (int)(n); ++u)
    if (!color[u] && !visit(g, u, order, color, next)) return false;
  reverse((order).begin(), (order).end());
  return true;
}
int n;
const int M = 5010;
char t[M][M];
vector<vector<Edge> > g;
vector<int> ans;
int main() {
  scanf("%d", &n);
  g.assign(n, vector<Edge>());
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%s", t[i]);
    for (int j = 0; j < (int)(n); ++j)
      if (t[i][j] == '1') g[i].push_back(Edge(i, j, 1));
  }
  vector<int> order;
  if (topologicalSort(g, order)) {
    cout << -1 << endl;
  } else {
    const int s = order[0];
    for (int i = 1; i < order.size() - 1; i++) {
      int d = order[i], d2 = order[i + 1];
      if (t[s][d2] == '1') {
      } else {
        ans.push_back(s);
        ans.push_back(d);
        ans.push_back(d2);
        break;
      }
    }
    if (ans.size() == 0) {
      assert(false);
    }
    cout << ans[0] + 1 << " " << ans[1] + 1 << " " << ans[2] + 1 << endl;
  }
  return 0;
}
