#include <bits/stdc++.h>
using namespace std;
bool g[5100][5100];
string str;
char h[5100];
short int mark[5100];
int n;
bool is = false;
vector<int> c, s;
void dfs(int v) {
  mark[v]++;
  s.push_back(v);
  for (int i = 0; i < (int)(n); i++) {
    if (is) {
      return;
    }
    if (!g[v][i]) {
      continue;
    }
    if (mark[i] == 0) {
      dfs(i);
    } else if (mark[i] == 1) {
      while (s[s.size() - 1] != i) {
        c.push_back(s[s.size() - 1]);
        s.pop_back();
      }
      c.push_back(i);
      is = true;
      return;
    }
  }
  s.pop_back();
  mark[v]++;
}
int main() {
  cin >> n;
  if (n < 3) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    scanf("%s", &h);
    str = h;
    for (int j = 0; j < (int)(n); j++) {
      g[i][j] = (str[j] == '1');
    }
    mark[i] = 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (!mark[i]) {
      dfs(i);
    }
    if (is) {
      break;
    }
  }
  vector<int> temp;
  for (int i = c.size() - 1; i >= 0; i--) {
    temp.push_back(c[i]);
  }
  c = temp;
  if (!is) {
    cout << -1;
    return 0;
  }
  int m = c.size();
  for (int i = 2; i < m; i++) {
    if (g[c[i]][c[0]]) {
      cout << c[0] + 1 << " " << c[i - 1] + 1 << " " << c[i] + 1;
      return 0;
    }
  }
}
