#include <bits/stdc++.h>
using namespace std;
char mmp[5005][5005];
int vis[5005];
int n;
int flag;
bool dfs(int u, int mark) {
  vis[u] = 1;
  for (int i = 1; i <= n; i++) {
    if (mmp[u][i] == '1') {
      if (mark != -1 && mmp[i][mark] == '1') {
        printf("%d %d %d", u, i, mark);
        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", mmp[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && dfs(i, -1)) return 0;
  }
  printf("-1");
  return 0;
}
