#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[] = {-1, 0, +1, 1, 1, 0, -1, -1};
long long int n;
vector<long long int> g[5007];
long long int taken[5007];
long long int parent[5007];
long long int v1_st, v1_end;
long long int v1_find(long long int a) {
  long long int i, b;
  taken[a] = 1;
  for (i = 0; i < g[a].size(); i++) {
    b = g[a][i];
    if (taken[b] == -1) {
      parent[b] = a;
      if (v1_find(b)) return 1;
    }
    if (taken[b] == 1) {
      v1_end = a;
      v1_st = b;
      return 1;
    }
  }
  taken[a] = 2;
  return 0;
}
char s1[5007];
vector<int> v1;
int ar1[5007][5007];
int main() {
  long long int i, a, b, c, j, l, k, m;
  memset(parent, -1, sizeof(parent));
  memset(taken, -1, sizeof(taken));
  v1_st = -1;
  memset(ar1, 0, sizeof(ar1));
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%s", s1);
    for (j = 0; j < n; j++) {
      if (s1[j] == '1') {
        g[i].push_back(j + 1);
        ar1[i][j + 1] = 1;
      } else
        ar1[i][j + 1] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    if (v1_find(i)) {
      break;
    }
  }
  if (v1_st == -1) {
    cout << "-1" << endl;
    return 0;
  }
  v1.push_back(v1_st);
  for (long long int v = v1_end; v != v1_st; v = parent[v]) v1.push_back(v);
  v1.push_back(v1_st);
  reverse(v1.begin(), v1.end());
  for (i = 0; i < v1.size() - 1; i++) {
    for (j = i + 1; j < v1.size() - 1; j++) {
      for (l = j + 1; l < v1.size() - 1; l++) {
        a = v1[i];
        b = v1[j];
        c = v1[l];
        if (ar1[a][b] == 1 && ar1[b][c] == 1 && ar1[c][a] == 1) {
          cout << a << " " << b << " " << c << endl;
          return 0;
        }
        if (ar1[b][a] == 1 && ar1[a][c] == 1 && ar1[c][b] == 1) {
          cout << a << " " << b << " " << c << endl;
          return 0;
        }
      }
    }
  }
}
