#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
int n, ans, u, qu[205];
char s[200][205];
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("\n%s", s[i]);
	rep(i,n){
		int de[205] = {}, b = 0, e = 0;
		de[qu[e++] = i] = 1;
		while(b < e){
			int t = qu[b++];
			rep(j,n) if(s[t][j] == '1'){
				if(de[j] == de[t]) return 0*puts("-1");
				if(!de[j]) u = de[qu[e++] = j] = de[t]+1;
			}
		}
		if(ans < u) ans = u;
	}
	printf("%d\n", ans);
}