#include <bits/stdc++.h>
using namespace std;
int b[5001], i, j, n, flag = 0, t;
char a[5001][5001];
void dfs(int x, int p) {
  if (flag) return;
  b[x] = ++t;
  for (int i = 0; i < n && flag == 0; ++i)
    if (a[x][i] == '1')
      if (!b[i]) {
        dfs(i, x);
      } else if (p == -1)
        continue;
      else if (a[i][p] == '1') {
        flag = 1;
        cout << i + 1 << ' ' << p + 1 << ' ' << x + 1;
      }
}
int main() {
  cin >> n;
  for (i = 0; i < n; ++i) scanf("%s", &a[i]);
  for (i = 0; i < n && !flag; ++i)
    if (!b[i]) dfs(i, -1);
  if (!flag) cout << -1;
  return 0;
}
