#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
string i_t_s(int x) {
  string t = "";
  while (x) {
    t += x % 10 + '0';
    x /= 10;
  }
  reverse(t.begin(), t.end());
  return t;
}
int s_t_i(string t) {
  int x = 0;
  for (int i = 0; i < t.size(); i++) {
    x = x * 10 + (t[i] - '0');
  }
  return x;
}
int n;
string s;
bool f[5001][5001];
vector<int> v[5001];
int visit[5001];
vector<int> c;
void ans(int x) {
  for (int i = c.size() - 2; i >= 0; i--) {
    if (f[x][c[i]]) {
      cout << x + 1 << " " << c[i] + 1 << " " << c[i + 1] + 1 << "\n";
      exit(0);
    }
  }
}
void dfs(int x) {
  visit[x] = 1;
  c.push_back(x);
  for (int i = 0; i < v[x].size(); i++) {
    if (visit[v[x][i]] == -1) continue;
    if (visit[v[x][i]]) {
      ans(v[x][i]);
    } else {
      dfs(v[x][i]);
    }
  }
  visit[x] = -1;
  c.pop_back();
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < n; j++)
      if (s[j] == '1') {
        v[i].push_back(j);
        f[i][j] = true;
      }
  }
  for (int i = 0; i < n; i++) {
    if (!visit[i]) {
      c.clear();
      dfs(i);
    }
  }
  cout << -1;
  return 0;
}
