#include <bits/stdc++.h>
using namespace std;
int n, mat[5003][5003], vis[5003];
int dfs(int x, int l) {
  vis[x] = 1;
  for (int j = 1; j <= n; j++) {
    if (mat[x][j]) {
      if (mat[j][l] && x != l && x != j && l != j) {
        cout << l << " " << x << " " << j;
        exit(0);
      }
      if (!vis[j]) dfs(j, x);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  char aux;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> aux;
      mat[i][j] = aux - '0';
    }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  cout << -1, 0;
  return 0;
}
