Under construction

Still being built. Things may change

Letter Balloons

Interview

Time limit1sMemory limit2048 MB

Summary
Given p problems and t school initials, find the largest number of schools that can each be the first solver of every problem spelled by their initials, with no overlap.
Level

Medium4 of 10

Topics
Bit manipulation, Brute force
Solved
No attempts yet

Problem

You are organizing a programming contest. The first team to solve each problem gets a balloon shaped like that problem's letter. For example, suppose there are twenty-three problems, labeled A through W. The members of Wossa Motta University want to be the first to solve problems M, U, and W, so they can fly their university's initials above their programming station. Many teams have the same idea and try to be the first solvers of the problems that spell their school's abbreviation. Both Wossa Motta U. and Spittinyer Institution might achieve this goal. Neither can do so if Muddinyer Institute solves problems M and I first. Muddinyer I. cannot achieve it if Wossa Motta U. or Spittinyer I. solves M or I first. Schools like Toe Tac Tech cannot succeed in any case, since a team can get at most one letter balloon for any problem. Xerxes College also cannot succeed, because this contest has no problem X. (We assume there is never a tie for the first solution to any problem.) What is the maximum number of teams that can display their school's initials with first-solver balloons at the end of the contest?

Input

The first line contains two integers pp and tt, where pp (1≤p≤261 \leq p \leq 26) is the number of problems and tt (1≤t≤201 \leq t \leq 20) is the number of teams. Problems are labeled with the first pp letters of the alphabet. Each of the following tt lines contains a nonempty string of at most 80 uppercase letters, the initials of a school. Each school has only one team, but several schools may have the same initials.

Output

Output a single integer: the maximum number of teams that can be the first solvers of all the problems that form the initials of their school name.

Examples2

  1. Example 1

    Input
    23 5
    WMU
    SI
    MI
    TTT
    XT
    
    Expected output
    2
    
  2. Example 2

    Input
    6 6
    ABC
    BDE
    ABE
    BF
    BF
    CEF
    
    Expected output
    1