#include <bits/stdc++.h>
using namespace std;
char A[5 << 10][5 << 10];
int B[5 << 10];
int P[5 << 10];
vector<int> res;
int n;
int dfs(int a, int p) {
  P[a] = p;
  B[a] = 1;
  int i;
  for (i = (0); i < (n); ++i)
    if (A[a][i] == '1') {
      if (B[i] == 0 && dfs(i, a)) return 1;
      if (B[i] == 1) {
        int t = a;
        while (t != i) {
          res.push_back(t);
          t = P[t];
        }
        res.push_back(t);
        reverse((res).begin(), (res).end());
        return 1;
      }
    }
  B[a] = -1;
  return 0;
}
int main() {
  scanf("%d", &n);
  int i;
  for (i = (0); i < (n); ++i) scanf("%s", A[i]);
  memset(B, 0, sizeof(B));
  for (i = (0); i < (n); ++i)
    if (B[i] == 0 && dfs(i, -1)) {
      vector<int> v = res;
      while (int((v).size()) != 3) {
        if (A[v[0]][v[int((v).size()) - 2]] == '1') {
          vector<int> w;
          w.push_back(v[0]);
          w.push_back(v[int((v).size()) - 2]);
          w.push_back(v[int((v).size()) - 1]);
          v = w;
        } else
          v.pop_back();
      }
      printf("%d %d %d\n", v[0] + 1, v[1] + 1, v[2] + 1);
      return 0;
    }
  printf("-1\n");
  return 0;
};
