#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
vector<long long int> g[5001];
long long int vis[5001], u, v, n, m;
bool edge[5001][5001];
void DFS(long long int cur, long long int par) {
  vis[cur] = 1;
  for (long long int i : g[cur]) {
    if (!vis[i]) {
      DFS(i, cur);
    } else {
      if (par != 0 && edge[i][par]) {
        cout << par << " " << cur << " " << i << endl;
        exit(0);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    string d;
    cin >> d;
    for (long long int j = 0; j < d.length(); j++) {
      if (d[j] == '1') {
        g[i + 1].push_back(j + 1);
        edge[i + 1][j + 1] = 1;
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      DFS(i, 0);
    }
  }
  cout << -1 << endl;
}
