### constant

UN = 5
TN = 10

INF = 1 << 30

### subroutines

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

def set_tt(att, tt, n, k, tid = true)
  for u in (0...UN)
    for i in (0...n)
      att[u][i + k] = tid if tt[u][i]
    end
  end
end

### main

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

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

  min_c = INF
  
  for dk in (1...n)
    att = UN.times.map{[]}

    k = 0
    TN.times do |tid|
      while conflict?(att, tt, n, k)
        k += 1
      end
      set_tt(att, tt, n, k, tid)
      k += dk - 1
    end
    #p att
  
    max_c = 0
    UN.times do |u|
      c = att[u].rindex{|c| ! c.nil?}
      max_c = c if c && max_c < c
    end

    min_c = max_c if min_c > max_c
  end

  puts min_c + 1
end