#include <bits/stdc++.h>
using namespace std;
int n;
bool ffree[5001];
char a[5001][5001];
bool dfs(int c, int p) {
  if (ffree[c]) return false;
  ffree[c] = true;
  for (int i = 0; i < n; ++i) {
    if (a[c][i] == '0') continue;
    if (a[p][c] == '1' && a[i][p] == '1')
      return printf("%d %d %d", p + 1, c + 1, i + 1);
    if (dfs(i, c)) return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%s", a[i]);
  memset(ffree, false, sizeof(ffree));
  for (int i = 0; i < n; ++i)
    if (!ffree[i] && dfs(i, i)) return 0;
  printf("-1\n");
  return 0;
}
