#include <bits/stdc++.h>
using namespace std;
int n;
char s[5001][5001] = {{}};
bool v[5001] = {};
void search(int x, int p) {
  v[x] = true;
  for (int i = 1; i <= n; ++i)
    if (s[x][i] == '1') {
      if (s[i][p] == '1') {
        cout << p << " " << x << " " << i << endl;
        exit(0);
      }
      if (!v[i]) search(i, x);
    }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; ++i)
    if (!v[i]) search(i, 0);
  cout << "-1" << endl;
  return 0;
}
