#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::getline;
using std::string;
using std::vector;
using std::ws;
size_t graph[5001][5001];
int dfs_num[5001];
size_t n;
void dfs(size_t p, size_t u);
int main(void) {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> ws;
  string line;
  for (size_t line_cnt = 0; line_cnt < n; line_cnt++) {
    getline(cin, line);
    for (size_t char_cnt = 0; char_cnt < n; char_cnt++)
      graph[line_cnt][char_cnt] = (line.at(char_cnt) == '1');
  }
  for (size_t counter = 0; counter < n; counter++)
    if (!dfs_num[counter]) {
      dfs_num[counter] = 1;
      dfs(-1, counter);
    }
  cout << -1 << endl;
  return 0;
}
void dfs(size_t p, size_t u) {
  for (size_t counter = 0; counter < n; counter++)
    if (graph[u][counter]) {
      if (!dfs_num[counter]) {
        dfs_num[counter] = 1;
        dfs(u, counter);
      } else if (p >= 0 && graph[counter][p]) {
        cout << counter + 1 << " " << p + 1 << " " << u + 1 << endl;
        exit(0);
      }
    }
}
