#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, a[N][N];
char s[N];
bool vis[N];
void dfs(int x, int fa) {
  vis[x] = 1;
  for (int i = 1; i <= n; i++) {
    if (!a[x][i] || i == fa || i == x) continue;
    if (a[i][fa]) printf("%d %d %d\n", x, i, fa), exit(0);
    if (!vis[i]) dfs(i, x);
  }
}
signed main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) a[i][j] = s[j] - '0';
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 0);
  puts("-1");
  return 0;
}
