#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
char mat[maxn][maxn];
int n;
int vis[maxn];
bool dfs(int x, int pre) {
  if (vis[x]) return 0;
  vis[x] = 1;
  for (int i = 0; i < n; i++) {
    if (mat[x][i] - '0') {
      if ((mat[i][pre] - '0') && (mat[pre][x] - '0')) {
        cout << pre + 1 << " " << x + 1 << " " << i + 1 << endl;
        return 1;
      }
      if (dfs(i, x)) return 1;
    }
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    scanf("%s", mat[i]);
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      if (dfs(i, i)) return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
