#include <bits/stdc++.h>
using namespace std;
bool ftim[5001];
char g[5001][5001];
bool visited[5001];
int parent[5001];
int n;
void Dfs(int head) {
  visited[head] = true;
  for (int i = 0; i < n; i++) {
    if (!visited[i] && g[head][i] == '1') {
      parent[i] = head;
      Dfs(i);
    } else if (g[head][i] == '1' && visited[i] && parent[head] != i &&
               !ftim[i]) {
      cout << i + 1 << " " << parent[head] + 1 << " " << head + 1;
      exit(0);
    }
  }
  ftim[head] = true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", &g[i]);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) Dfs(i);
  }
  cout << -1;
  return 0;
}
