#include <bits/stdc++.h>
using namespace std;
int qsize = 0;
bool fr = 0;
int bt = 1;
bool ended[5000];
bool bq = 0;
vector<string> inp;
set<int> all;
set<int> none;
void print_q(int *q, int x) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n = 2;
  for (int i = 0; i < n; i++) {
    cout << q[i] + 1 << " ";
  }
  cout << x + 1 << '\n';
  exit(0);
}
void _3loop(int i, vector<vector<int> > &v, int *visited, int *q) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  qsize++;
  q[qsize] = i;
  visited[i] = 1;
  bool retrieve = 0;
  if (qsize > 1) {
    q++;
    qsize--;
    retrieve = 1;
  }
  int n = v[i].size();
  for (int j = 0; j < n; j++) {
    if (retrieve) {
      if (inp[v[i][j]][q[0]] == '1') print_q(q, v[i][j]);
    }
    if (!visited[v[i][j]]) _3loop(v[i][j], v, visited, q);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int *vi, *x;
  int n;
  cin >> n;
  vector<vector<int> > v;
  vi = (int *)malloc(n * sizeof(int));
  x = (int *)malloc((n + 1) * sizeof(int));
  for (int i = 0; i < n; i++) {
    vi[i] = 0;
    ended[i] = 0;
    v.push_back({});
    inp.push_back("");
    cin >> inp[i];
    for (int j = 0; j < n; j++) {
      if (inp[i][j] == '1') {
        v[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (vi[i] == 0) {
      qsize = 0;
      _3loop(i, v, vi, x);
    }
  }
  cout << -1;
  return 0;
}
