N = gets.to_i
S = N.times.map{
	gets.strip.chars.map{|_| _=='1' }
}

d = [nil]*N
(0..(N-2)).each{|i|
	((i+1)..(N-1)).each{|j|
		next unless S[i][j]
		d[i] = true if d[i].nil?
		d[j] = ! d[i] if d[j].nil?
		if d[i] == d[j]
			p(-1)
			exit
		end
	}
}
