N = gets.to_i
S = N.times.map{
	gets.to_i(2)
}
D = lambda{|i0|
	d, p, q, r, r_1 = -1, 0, 1<<(N-1-i0), 0, 0
	until q == 0
		raise if 0 != q&r_1
		d, p, q, r = d+1, p|q, 0, (p^q)&q
		r_1 = r
		until 0 == (s = r&(-r))
			q |= S[N-s.bit_length]
			r ^= s
		end
	end
	return d
}
p ((0...N).map(&D).max rescue -1)
