const fs = require("fs")
const [num, ...arr] = fs.readFileSync("./test").toString().trim().split("\n")
let maxContinuous = 0
const board = arr.map(v => v.split(""))
for (let i = 0; i < num; i++) {
const continuousX = new Set()
const continuousY = new Set()
for (let j = 0; i < num; j++) {
continuousX.add(board[i][j])
continuousY.add(board[i][j])
}
const temp = Math.max(num - continuousX.size(), num - continuousY.size())
const continuous = temp === 1 ? 0 : temp + 1
if (continuous > maxContinuous) {
maxContinuous = continuous
}
}
if (maxContinuous === num) {
console.log(num)
process.exit(0)
}
const search = pickArr => {
const temp = new Set(pickArr)
const continuous = num - temp.size() === 1 ? 0 : temp.size() + 1
if (continuous > maxContinuous) {
maxContinuous = continuous
}
}
for (let i = 0; i < num; i++) {
for (let j = 1; j < num; j++) {
if (board[i][j - 1] !== board[i][j]) {
const tempXArr = [...board[i]]
tempXArr[j] = board[i][j - 1]
tempXArr[j - 1] = board[i][j]
search(tempXArr)
}
}
}