#include <bits/stdc++.h>
using namespace std;
char arr[5000 + 10][5000 + 10];
int check[5000 + 10];
int n;
void rec(int current, int previ) {
  if (check[current] == 0) {
    check[current] = 1;
    for (int j = 0; j < n; j++) {
      if (arr[current][j] == '1') {
        if (arr[j][previ] == '1') {
          printf("%d %d %d", previ + 1, current + 1, j + 1);
          exit(0);
        }
        if (check[j] == 0) rec(j, current);
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", arr[i]);
  for (int i = 0; i < n; i++) {
    if (check[i] == 0) rec(i, i);
  }
  printf("-1");
  return 0;
}
