#include <bits/stdc++.h>
using namespace std;
int n;
char grid[5050][5050];
bool visited[5050];
void dfs(int i, int prev) {
  visited[i] = true;
  for (int k = 0; k < n; k++) {
    if (grid[i][k] == '1') {
      if (grid[k][prev] == '1') {
        printf("%d %d %d", prev + 1, i + 1, k + 1);
        exit(0);
      } else if (!visited[k])
        dfs(k, i);
    }
  }
  return;
}
int main() {
  scanf(" %d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", &grid[i]);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) dfs(i, -1);
  }
  printf("-1");
  return 0;
}
