### constant

UN = 5
TN = 10

INF = 1 << 30

### subroutines

def conflict_tt?(att, tt, k)
  for u in (0...UN)
    for i in (0...$n)
      return true if att[u][k + i] && tt[u][i]
    end
  end
  false
end

def c_rec(i, k)
  #p ["c_rec", i, k]
  if i >= TN
    return k - 1
  end

  min_c = INF
  bcfls = []
  
  for dk in (0...$n)
    k0 = k + dk
    break if k0 > min_c

    if $acfls[k0].nil?
      for j in (0...$n)
        bcfls[j] = $acfls[k0 + j]
        $acfls[k0 + j] = 1 if $ucfls[j]
      end

      c = c_rec(i + 1, k0 + 1)
      min_c = c if min_c > c

      for j in (0...$n)
        $acfls[k0 + j] = bcfls[j]
      end
    end
  end

  min_c
end

### main

loop do
  $n = gets.to_i
  break if $n == 0

  utt = UN.times.map{gets.strip.split('').map{|ch| ch == 'X'}}
  #p utt

  $ucfls = [1] + (1...$n).map{|k| conflict_tt?(utt, utt, k) ? 1 : nil}
  #p $ucfls

  $acfls = $ucfls.clone
  #p $acfls

  min_c = c_rec(1, 1)

  puts min_c + $n
end