#include <bits/stdc++.h>
using namespace std;
const int MAX = 5010;
bool a[MAX][MAX], vis[MAX];
vector<int> ad[MAX];
void dfs(int v, int p) {
  vis[v] = true;
  for (auto u : ad[v]) {
    if (vis[u]) {
      if (a[u][p]) {
        cout << v + 1 << " " << u + 1 << " " << p + 1;
        exit(0);
      }
      continue;
    }
    if (a[u][p]) {
      cout << v + 1 << " " << u + 1 << " " << p + 1;
      exit(0);
    }
    dfs(u, v);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char s[MAX];
    cin >> s;
    for (int j = 0; j < n; j++) {
      if (s[j] == '0')
        a[i][j] = 0;
      else
        a[i][j] = 1;
      if (a[i][j]) ad[i].push_back(j);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) dfs(i, -1);
  }
  cout << -1;
}
