#include <bits/stdc++.h>
using namespace std;
int v, E;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> count(n + 1, 0);
  vector<string> a;
  for (long long int i = 0; i < n; i++) {
    string s;
    cin >> s;
    a.push_back(s);
    for (long long int j = 0; j < n; j++) {
      if (s[j] == '1') {
        count[i] += 1;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if (a[i][j] == '1' && count[i] <= count[j]) {
        for (long long int k = 0; k < n; k++) {
          if (a[j][k] == '1' && a[k][i] == '1') {
            cout << k + 1 << " " << i + 1 << " " << j + 1 << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << "-1" << endl;
}
