#include <bits/stdc++.h>
using namespace std;
char field[5000][5001];
stack<int> st;
int n;
int isVisit[5000];
int ans[3];
void dfs(int cur);
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", field[i]);
  ans[0] = -1;
  for (int i = 0; i < n; i++) {
    if (!isVisit[i]) {
      dfs(i);
      while (!st.empty()) st.pop();
    }
    if (ans[0] != -1) break;
  }
  if (ans[0] == -1) printf("-1\n");
  return 0;
}
void dfs(int cur) {
  isVisit[cur] = 1;
  st.push(cur);
  for (int i = 0; i < n; i++) {
    if (field[cur][i] == '1') {
      if (isVisit[i] == 1 && ans[0] == -1) {
        vector<int> list;
        int top;
        stack<int> _st = st;
        do {
          top = st.top();
          st.pop();
          list.push_back(top);
        } while (top != i && !st.empty());
        st = _st;
        for (int i = list.size() - 1; i >= 2; i--) {
          int v1 = list[0];
          int v2 = list[i - 1];
          if (field[v2][v1] == '1') {
            printf("%d %d %d\n", list[0] + 1, list[i] + 1, list[i - 1] + 1);
            ans[0] = 0;
            break;
          }
        }
      } else {
        if (isVisit[i]) continue;
        dfs(i);
      }
    }
  }
  isVisit[cur] = 2;
  if (!st.empty() && st.top() == cur) st.pop();
  return;
}
