#include <bits/stdc++.h>
using namespace std;
const bool debug = false;
const int maxn = 5001;
bitset<maxn> g[maxn];
int used[maxn];
int n;
void printAnswer(int s, int f) {
  for (int i = 0; i < n; i++)
    if (g[s].test(i) && g[i].test(f))
      cout << s + 1 << " " << i + 1 << " " << f + 1 << endl, exit(0);
}
int dfs(int v) {
  if (used[v] == 2) return 0;
  if (used[v] == 1) return 1;
  used[v] = 1;
  for (int i = 0; i < n; i++)
    if (g[v].test(i) && dfs(i)) return 1;
  used[v] = 2;
  return 0;
}
inline char nextChar() {
  while (char c = getchar())
    if (c == '0' || c == '1') return c;
  return 0;
}
int main() {
  scanf("%d\n", &n);
  char c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) c = nextChar(), g[i].set(j, c == '1');
  if (debug) cerr << (double)clock() / CLOCKS_PER_SEC << endl;
  memset(used, 0, sizeof(used));
  bool ok = true;
  for (int i = 0; i < n; i++)
    if (used[i] == 0 && dfs(i)) {
      ok = false;
      if (debug) cerr << i << endl;
    }
  if (debug) cerr << (double)clock() / CLOCKS_PER_SEC << endl;
  if (ok) printf("-1"), exit(0);
  for (int i = 0; i < n; i++) {
    bitset<maxn> good;
    for (int j = 0; j < n; j++) {
      if (!g[i].test(j)) continue;
      good |= g[j];
    }
    for (int j = 0; j < n; j++)
      if (good.test(j) && g[j].test(i)) printAnswer(i, j);
  }
  cout << -1 << endl;
  if (debug) cerr << (double)clock() / CLOCKS_PER_SEC << endl;
  return 0;
}
