#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 5000 + 10;
int mark[MAX_S], vv;
bool push_in = false;
bool jj[MAX_S][MAX_S], isgood = false;
vector<int> adj[MAX_S], cycle;
void DFS(int s) {
  mark[s] = 1;
  for (int i = 0; !isgood && i < adj[s].size(); i++) {
    int u = adj[s][i];
    if (!mark[u])
      DFS(u);
    else if (mark[u] == 1) {
      isgood = true;
      push_in = true;
      vv = u;
    }
  }
  mark[s] = 2;
  if (push_in) cycle.push_back(s);
  if (s == vv) push_in = false;
}
int main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    for (int j = 0; j < t.size(); j++) {
      if (t[j] == '1') {
        jj[i][j] = true;
        adj[i].push_back(j);
      }
    }
  }
  for (int i = 0; !isgood && i < n; i++) {
    if (!mark[i]) DFS(i);
  }
  if (cycle.empty()) {
    cout << -1 << endl;
    return 0;
  }
  reverse(cycle.begin(), cycle.end());
  int place = 1;
  while (true) {
    if (jj[cycle[place + 1]][cycle[0]]) {
      cout << cycle[0] + 1 << ' ' << cycle[place] + 1 << ' '
           << cycle[place + 1] + 1 << endl;
      break;
    } else
      place++;
  }
  return 0;
}
