N = gets.to_i S = N.times.map{ gets[0,N] } res = N.times.map{[nil]*N} S.each_with_index{|s, i| s.chars.each_with_index{|c, ii| res[i][ii] = c } } N.times{|x| if res[0][x] == ?- res[0][x] = ?o res[x][0] = ?x end } while res.any?{|a|a.any?{|c|c == ?-}} y = res.min_by{|a|[-a.count(?o), -a.count(?-)]}.index(?#) x = res[y].index(?-) res[y][x] = ?x res[x][y] = ?o end win = res[0].count(?o) p 1 + res.map{|a|a.count(?o)}.sort_by{|o|-o}.uniq.index(win)