#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 5002;
int n, par[N];
string s[N];
bool in[N];
vector<int> cyc;
void dfs(int u) {
  in[u] = 1;
  for (int v = (1); v <= (n); ++v)
    if (v != u && s[u][v] == '1') {
      if (!par[v]) {
        par[v] = u;
        dfs(v);
      } else if (in[v]) {
        for (; u != v; u = par[u]) cyc.emplace_back(u);
        cyc.emplace_back(v);
        reverse((cyc).begin(), (cyc).end());
        for (int i = (1); i <= (((int)(cyc).size()) - 2); ++i)
          if (s[cyc[i + 1]][cyc[0]] == '1') {
            cout << cyc[0] << ' ' << cyc[i] << ' ' << cyc[i + 1];
            exit(0);
          }
      }
    }
  in[u] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = (1); i <= (n); ++i) cin >> s[i], s[i] = '0' + s[i];
  for (int i = (1); i <= (n); ++i)
    if (!par[i]) {
      par[i] = i;
      dfs(i);
    }
  cout << -1;
  return 0;
}
