#include <bits/stdc++.h>
using namespace std;
char Map[5001][5001];
int n;
bool visit[5001];
bool dfs(int x, int pre = -1) {
  visit[x] = 1;
  for (int i = 0; i < n; ++i)
    if (Map[x][i] == '1') {
      if (Map[i][pre] == '1') {
        printf("%d %d %d\n", pre + 1, x + 1, i + 1);
        return 1;
      }
      if (!visit[i] && dfs(i, x)) return 1;
    }
  return 0;
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%s", Map[i]);
  for (i = 0; i < n; ++i)
    if (!visit[i] && dfs(i)) return 0;
  printf("-1\n");
}
