#include <bits/stdc++.h>
using namespace std;
char connect[5000][5001];
int color[5000];
int previous[5000];
int N;
bool found = false;
bool isCycle(int a, int b, int c) {
  return connect[a][b] == '1' and connect[b][c] == '1' and connect[c][a] == '1';
}
void dfs(int node) {
  color[node] = 1;
  for (int i = 0; i < N; ++i) {
    if (!found and connect[node][i] == '1') {
      if (color[i] == 0) {
        previous[i] = node;
        dfs(i);
      } else if (color[i] == 1) {
        vector<int> seq;
        int now = node;
        while (now != -1) {
          seq.push_back(now);
          if (now == i) break;
          now = previous[now];
        }
        for (int j = 0; j < seq.size(); ++j) {
          if (isCycle(seq[j + 1], seq[j], i)) {
            found = true;
            cout << seq[j + 1] + 1 << " " << seq[j] + 1 << " " << i + 1 << endl;
            break;
          }
        }
      }
    }
  }
  color[node] = 2;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    scanf("%s", connect[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (color[i] == 0) {
      previous[i] = -1;
      dfs(i);
    }
  }
  if (!found) {
    cout << -1 << endl;
  }
  return 0;
}
