#include <bits/stdc++.h>
const int MOD = (1 << 9) + 7;
using namespace std;
struct rcnt {
  int cnt;
  int r;
};
bool operator<(const rcnt &a, const rcnt &b) {
  if (a.cnt == b.cnt) {
    return a.r < b.r;
  }
  return a.cnt < b.cnt;
}
char g[5010][5010];
bool solve(const vector<int> &all) {
  int N = (int)(all).size();
  if (N < 3) return 0;
  vector<int> out, in;
  int x = all[0];
  for (int i = (1); i < (N); i++)
    if (g[x][all[i]] == '1')
      out.push_back(all[i]);
    else
      in.push_back(all[i]);
  for (int i = 0; i < ((int)(out).size()); i++) {
    for (int j = 0; j < ((int)(in).size()); j++) {
      if (g[out[i]][in[j]] == '1') {
        cout << x + 1 << " " << out[i] + 1 << " " << in[j] + 1 << endl;
        return 1;
      }
    }
  }
  if ((int)(out).size() > 2) {
    if (solve(out)) return 1;
  }
  if ((int)(in).size() > 2) {
    if (solve(in)) return 1;
  }
  return 0;
}
int main(void) {
  int N;
  char t;
  cin >> N;
  for (int i = 0; i < (N); i++) {
    scanf(" %s", g[i]);
  }
  vector<int> all;
  for (int i = 0; i < (N); i++) all.push_back(i);
  random_shuffle(all.begin(), all.end());
  if (solve(all)) return 0;
  cout << -1 << endl;
}
