#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > vec;
char s[5001][5001];
int x, y, z;
int vis[5001];
bool check = false;
int solve(int u, int parent) {
  vis[u] = 1;
  int ans = 0;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (parent != -1 && s[v][parent] == '1') {
      x = u;
      y = parent;
      z = v;
      return 1;
    }
    if (vis[v] == 0) ans |= solve(v, u);
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vec.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < n; j++) {
      if (s[i][j] == '1') vec[i].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    if (vis[i] == 0 && solve(i, -1)) {
      cout << y + 1 << " " << x + 1 << " " << z + 1 << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
