#include <bits/stdc++.h>
using namespace std;
vector<long> vc[5050];
long a, b, c, flag, n, prs, i, j, vis[5050];
char st[5050][5050];
void find(long n, long par) {
  if (flag) return;
  vis[n] = 1;
  for (int i = 0; i < vc[n].size(); i++)
    if (vis[vc[n][i]] == 0)
      find(vc[n][i], n);
    else if (st[vc[n][i]][par] == '1') {
      flag = 1;
      a = vc[n][i];
      b = par;
      c = n;
    }
}
int main() {
  while (~scanf("%ld", &n)) {
    for (i = 0; i < n; i++) scanf("%s", st[i]), vc[i].clear(), vis[i] = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        if (st[i][j] == '1') vc[i].push_back(j);
    flag = 0;
    for (i = 0; i < n; i++)
      if (vis[i] == 0) find(i, -1);
    if (flag)
      printf("%ld %ld %ld\n", a + 1, b + 1, c + 1);
    else
      printf("-1\n");
  }
  return 0;
}
