#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
int n;
const int N = 5e3 + 5;
bool vis[N];
bool flag = 0;
char adj[N][N];
void dfs(int s, int p) {
  vis[s] = 1;
  for (int i = 0; i < n && !flag; i++) {
    if (adj[s][i] == '1') {
      if (adj[i][p] == '1') {
        printf("%d %d %d\n", i + 1, p + 1, s + 1);
        flag = 1;
        break;
      } else if (!vis[i])
        dfs(i, s);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s", adj[i]);
  }
  for (int i = 0; i < n && !flag; i++) {
    if (!vis[i]) dfs(i, i);
  }
  if (!flag) printf("%d\n", -1);
  return 0;
}
