#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<int> adj[N];
int dfn[N], flag;
void dfs(int u, int pre) {
  if (flag) return;
  dfn[u] = 1;
  int len = (int)adj[u].size();
  for (int i = 0; i < len; i++) {
    int v = adj[u][i];
    if (dfn[v] == -1) dfs(v, u);
    if (pre != -1 && flag == 0) {
      int pos = lower_bound(adj[v].begin(), adj[v].end(), pre) - adj[v].begin();
      if (pos >= 0 && pos < (int)adj[v].size() && adj[v][pos] == pre) {
        flag = 1;
        printf("%d %d %d\n", pre + 1, u + 1, v + 1);
        return;
      }
    }
  }
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    flag = 0;
    memset(dfn, -1, sizeof(dfn));
    for (int i = 0; i < N; i++) adj[i].clear();
    for (int i = 0; i < n; i++) {
      char str[N];
      scanf("%s", str);
      for (int j = 0; j < n; j++)
        if (str[j] == '1') {
          adj[i].push_back(j);
        }
    }
    for (int i = 1; i <= n; i++)
      if (dfn[i] == -1) dfs(i, -1);
    if (flag == 0) puts("-1");
  }
  return 0;
}
