#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int matr[5000][5000];
int w[5000];
int st[5000], en[5000];
int ct = 1;
int go(int x) {
  w[x] = 1;
  st[x] = ct++;
  for (int i = 0; i < (n); i++)
    if (matr[x][i]) {
      if (w[i]) {
        if (en[i] == 0) return i;
      } else {
        int tmp = go(i);
        if (tmp != -1) return tmp;
      }
    }
  en[x] = ct++;
  return -1;
}
int main() {
  cin >> n;
  char s[10000];
  gets(s);
  for (int i = 0; i < (n); i++) {
    gets(s);
    for (int j = 0; j < (n); j++) matr[i][j] = s[j] == '1';
  }
  for (int j = 0; j < (n); j++) {
    if (!w[j]) {
      int tmp = go(j);
      if (tmp != -1) {
        for (int a = 0; a < (n); a++)
          for (int b = 0; b < (n); b++)
            if (matr[tmp][a] == 1 && matr[a][b] == 1 && matr[b][tmp] == 1) {
              cout << tmp + 1 << ' ' << a + 1 << ' ' << b + 1 << endl;
              return 0;
            }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
