#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n;
char s[N][N];
bool flag[N];
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
}
void dfs(int x, int p) {
  flag[x] = true;
  for (int i = 1; i <= n; i++)
    if (s[x][i] == '1') {
      if (s[i][p] == '1') {
        printf("%d %d %d\n", p, x, i);
        exit(0);
      }
      if (!flag[i]) dfs(i, x);
    }
}
void work() {
  memset(flag, false, sizeof(flag));
  for (int i = 1; i <= n; i++)
    if (!flag[i]) dfs(i, 0);
  printf("-1\n");
}
int main() {
  init();
  work();
  return 0;
}
