#include <bits/stdc++.h>
#pragma 03
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const short maxn = 5002;
vector<short> adj[maxn];
short visited[maxn], par[maxn];
char ch[maxn][maxn];
vector<vector<short> > ans;
void cycle(short x, short p) {
  if (visited[x] == 2) return;
  if (visited[x] == 1) {
    short i = p;
    vector<short> tmp;
    tmp.emplace_back(p);
    while (i != x) {
      i = par[i];
      tmp.emplace_back(i);
    }
    reverse(tmp.begin(), tmp.end());
    i = 0;
    while (tmp.size() >= 3) {
      short a = tmp[0], b = tmp[1], c = tmp[2];
      if (ch[c][a] == '1') {
        cout << a << ' ' << b << ' ' << c;
        exit(0);
      }
      tmp.erase(tmp.begin() + 1);
    }
  }
  par[x] = p;
  visited[x] = 1;
  for (short i : adj[x])
    if (i != par[x]) cycle(i, x);
  visited[x] = 2;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  short n;
  cin >> n;
  for (short i = 1; i <= n; ++i)
    for (short j = 1; j <= n; ++j) {
      cin >> ch[i][j];
      if (ch[i][j] == '1') adj[i].emplace_back(j);
    }
  for (short i = 1; i <= n; ++i) cycle(i, 0);
  if (ans.size() == 0) {
    cout << -1;
    return 0;
  }
}
