#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
char ch[maxn];
int e[maxn][maxn];
bool use[maxn];
bool mark[maxn][maxn];
int n;
int a1, a2, a3;
bool f;
void dfs(int ye, int fa, int now) {
  use[now] = true;
  if (f) return;
  for (; e[now][0] >= 1; e[now][0]--) {
    if (f) return;
    int k = e[now][e[now][0]];
    if (mark[now][k]) continue;
    if (k == ye) {
      a1 = ye;
      a2 = fa;
      a3 = now;
      f = true;
      return;
    } else {
      mark[now][k] = true;
      dfs(fa, now, k);
    }
  }
}
bool slove() {
  for (int i = 1; i <= n; i++) {
    if (use[i]) continue;
    use[i] = true;
    f = false;
    dfs(-1, -1, i);
    if (f) {
      printf("%d %d %d\n", a1, a2, a3);
      return true;
    }
  }
  return false;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch);
    for (int j = 0; j < n; j++) {
      if (ch[j] == '1') {
        e[i][0]++;
        e[i][e[i][0]] = j + 1;
      }
    }
  }
  if (!slove()) puts("-1");
}
