#include <bits/stdc++.h>
using namespace std;
int n, cur;
char adj_mat[5005][5005];
bool vis[5005];
char a;
bool DFS(int s, int e) {
  vis[s] = 1;
  for (int i = 1; i <= n; i++) {
    if (adj_mat[s][i] == '1') {
      if (adj_mat[i][e] == '1') {
        cout << e << " " << s << " " << i << "\n";
        return 1;
      }
      if (!vis[i])
        if (DFS(i, s)) return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", adj_mat[i] + 1);
  for (int i = 1; i <= n; i++) {
    if (DFS(i, i)) return 0;
  }
  return puts("-1");
}
