#include <bits/stdc++.h>
using namespace std;
vector<int> vis(5005, 0), now(5005, 0);
int n;
vector<string> adj;
int dfs(int v, int p) {
  vis[v] = 1;
  now[v] = 1;
  for (int i = 0; i < n; i++) {
    if (adj[v][i] == '0') continue;
    int x = i;
    if (vis[x] == 1 && now[x] == 1) {
      if (adj[x][p] == '1')
        cout << p + 1 << " " << v + 1 << " " << x + 1 << endl;
      exit(0);
    }
    if (vis[x] == 1) continue;
    dfs(x, v);
  }
  now[v] = 0;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string second;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> second;
    adj.push_back(second);
  }
  for (int i = 0; i < n; i++)
    if (vis[i] == 0) dfs(i, -1);
  cout << "-1" << endl;
}
