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