#include <bits/stdc++.h>
using namespace std;
char grid[5003][5003];
int v[5003];
int r = 0;
bool comp(const int a, const int b) { return grid[r][a] > grid[r][b]; }
bool solve(int b, int e) {
  if (b >= e) return false;
  r = v[b];
  int m = b + 1;
  sort(v + b + 1, v + e, comp);
  while (m < e && grid[r][v[m]]) ++m;
  for (int i = b; i < m; ++i)
    for (int j = m; j < e; ++j)
      if (grid[v[i]][v[j]]) {
        printf("%d %d %d\n", r + 1, v[i] + 1, v[j] + 1);
        return true;
      }
  return solve(b + 1, m) || solve(m, e);
}
int main() {
  int N;
  while (scanf("%d", &N) == 1) {
    for (int i = 0; i < N; ++i) {
      scanf("%s", grid[i]);
      v[i] = i;
    }
    for (int i = 0; i < N; ++i)
      for (int j = 0; j < N; ++j) grid[i][j] -= '0';
    if (!solve(0, N)) printf("-1\n");
  }
  return 0;
}
