#include <bits/stdc++.h>
using namespace std;
const long long int hell = 1000000007;
const long long int maxn = 5e3 + 5;
long long int g[maxn][maxn];
bool vis[maxn];
long long int n;
void dfs(long long int v, long long int p) {
  vis[v] = 1;
  for (long long int i = 1; i <= n; i++) {
    if (!g[v][i]) continue;
    if (g[i][p]) {
      cout << p << ' ' << v << ' ' << i;
      exit(0);
    }
    if (!vis[i]) dfs(i, v);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= n; j++) {
      char x;
      cin >> x;
      g[i][j] = x - '0';
    }
  }
  for (long long int i = 1; i <= n; i++) {
    dfs(i, 0);
  }
  cout << -1;
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
}
