#include <bits/stdc++.h>
using namespace std;
bool pd[5005][5005];
char str[5005];
int n;
bool vis[5050];
bool dfs(int u, int lst) {
  vis[u] = 1;
  for (int i = 1; i <= n; ++i) {
    if (!pd[u][i]) continue;
    if (lst != -1 && pd[i][lst]) {
      printf("%d %d %d\n", lst, u, i);
      return 1;
    }
    if (!vis[i] && dfs(i, u)) return 1;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    for (int j = 1; j <= n; ++j)
      if (str[j] == '1') pd[i][j] = 1;
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i] && dfs(i, -1)) {
      return 0;
    }
  printf("-1\n");
  return 0;
}
