#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5010;
char G[MAX_N][MAX_N];
int vis[MAX_N];
int a1, a2, a3, n;
bool ok;
void dfs(int x, int p) {
  vis[x] = true;
  if (ok) return;
  for (int y = 1; y <= n; y++)
    if (G[x][y] == '1' && !ok) {
      if (G[y][p] == '1') {
        ok = true;
        a1 = p, a2 = x, a3 = y;
        return;
      } else if (!vis[y]) {
        dfs(y, x);
      }
    }
}
int main() {
  cin >> n;
  gets(*G);
  for (int i = 1; i <= n; i++) gets(G[i] + 1);
  for (int i = 1; i <= n; i++)
    if (!vis[i] && !ok) {
      dfs(i, 0);
    }
  if (ok)
    cout << a1 << " " << a2 << " " << a3 << endl;
  else
    cout << "-1" << endl;
  return 0;
}
