#include <bits/stdc++.h>
using namespace std;
const long long int p_mod = 9999999999999983;
const long double pi = 3.14159265358979323;
const long long int N = 5e3 + 9;
const long long int mod = 1e9 + 7;
vector<long long int> v[N];
long long int vis[N], level[N];
string s[N];
int dfs(long long int x, long long int papa) {
  vis[x] = 1;
  level[x] = level[papa] + 1;
  for (auto it : v[x]) {
    if (vis[it]) {
      if (level[x] - level[it] == 2 && s[it - 1][papa - 1] == '1') {
        cout << it << " " << papa << " " << x << '\n';
        return -1;
      }
    } else {
      long long int l = dfs(it, x);
      if (l == -1) return -1;
    }
  }
  return 1;
}
void solve() {
  long long int n, m;
  cin >> n;
  for (int i = 0; i <= n - 1; ++i) cin >> s[i];
  for (int i = 0; i <= n - 1; ++i) {
    for (int j = 0; j <= n - 1; ++j)
      if (s[i][j] == '1') v[i + 1].push_back(j + 1);
  }
  for (int i = 1; i <= n; ++i)
    if (vis[i] == 0)
      for (auto it : v[i])
        if (it > i) {
          level[i] = 0;
          long long int l = dfs(it, i);
          if (l == -1) return;
        }
  cout << -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) solve();
}
