#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long double eps = 1e-9;
const long double pi = fabs(atan2(0.0, -1.0));
int n;
char a[5005][5005];
void Load() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    gets(a[i]);
    for (int j = 0; j < n; j++) a[i][j] -= '0';
  }
}
int sz;
int pth[5005];
int was[5005];
bool dfs(int v) {
  was[v] = 1;
  pth[sz++] = v;
  for (int i = 0; i < n; i++) {
    if (a[v][i] == 0 || was[i] == 2) continue;
    if (was[i] == 1) {
      int j;
      for (j = sz - 1; j >= 0 && pth[j] != i; j--)
        ;
      for (int k = j; k < sz; k++) pth[k - j] = pth[k];
      sz = sz - j;
      return true;
    }
    if (dfs(i)) return true;
  }
  was[v] = 2;
  sz--;
  return false;
}
void Solve() {
  for (int i = 0; i < n; i++)
    if (was[i] == 0) {
      sz = 0;
      if (dfs(i)) {
        for (int j = 0; j < sz; j++) {
          int v1 = pth[j];
          int v2 = pth[(j + 1) % sz];
          int v3 = pth[(j + 2) % sz];
          if (a[v1][v2] == 1 && a[v2][v3] == 1 && a[v3][v1] == 1) {
            printf("%d %d %d\n", v1 + 1, v2 + 1, v3 + 1);
            return;
          }
        }
      }
    }
  printf("-1");
}
int main() {
  Load();
  Solve();
  return 0;
}
