#include <bits/stdc++.h>
using namespace std;
char M[5011][5011];
vector<int> to[5231];
int n;
int main() {
  while (cin >> n) {
    gets(M[0]);
    for (int i = 0; i < n; i++) {
      gets(M[i]);
      int s = 0;
      for (int q = 0; q < n; q++) M[i][q] -= '0', s += M[i][q];
      to[s].push_back(i);
    }
    for (int i = 0; i < n; i++) {
      if (to[i].size() >= 2) {
        int a = to[i][0], b = to[i][1];
        if (M[a][b]) {
          for (int i = 0; i < n; i++) {
            if (M[b][i] && M[i][a]) {
              cout << a + 1 << " " << b + 1 << ' ' << i + 1 << endl;
              return 0;
            }
          }
        } else {
          for (int i = 0; i < n; i++) {
            if (M[i][b] && M[a][i]) {
              cout << a + 1 << ' ' << i + 1 << " " << b + 1 << endl;
              return 0;
            }
          }
        }
      }
    }
    cout << -1 << endl;
  }
}
