#include <bits/stdc++.h>
using namespace std;
bool pa[5005][5005];
int vis[5005];
vector<int> gr[5005];
int ans[5], f = 0;
int dp[5005];
char str[5005][5005];
void dfs(int pre, int src) {
  vis[src] = 1;
  if (f) return;
  int i, len, u;
  len = gr[src].size();
  for (i = 0; i < len; i++) {
    u = gr[src][i];
    if (f) return;
    if (pa[u][pre] == 1) {
      cout << pre << " " << src << " " << u << endl;
      f = 1;
    } else if (vis[u] == 0) {
      dfs(src, u);
    }
  }
}
int main() {
  int n, i, j, len;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%s", str[i]);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      pa[i][j] = str[i - 1][j - 1] - '0';
      if (pa[i][j] == 1) gr[i].push_back(j);
    }
  }
  for (i = 1; i <= n; i++) {
    if (f) return 0;
    if (vis[i] == 0) dfs(0, i);
  }
  if (f == 0) cout << -1 << endl;
}
