Letter Balloons

시간 제한1초메모리 제한2048 MB

요약
p개의 문제와 t개 팀의 이니셜 문자열이 주어질 때, 자기 이름의 모든 글자에 대한 첫 해결 풍선을 차지할 수 있는 팀 수의 최댓값을 구한다. 글자당 풍선은 최대 하나이며 각 문제의 첫 해결 팀은 겹치지 않는다.
난이도

보통10점 중 7점

유형
백트래킹, 그리디, 비트 연산
정답자
아직 제출이 없습니다

문제

You are organizing a programming contest, and have decided that the first team to solve each problem will get a balloon in the shape of the problem's letter. For example, suppose there are twenty-three problems in the contest, labeled A through W. The team members for Wossa Motta University are hoping to be first to solve problems M, U, and W so that they can fly their university's initials above their programming station. In fact, a lot of teams have the same idea: try to be first-solvers of problems that spell out their school's abbreviation. It might be possible for both Wossa Motta U. and the Spittinyer Institution to achieve this goal, but neither will be able to do so if Muddinyer Institute manages to solve problems M and I before they do (we are assuming there will never be a tie for the first solution to any problem). On the other hand, Muddinyer I. can't achieve it if either Wossa Motta U. or Spittinyer I. solves M or I first. Schools like Toe Tac Tech are out of luck no matter what, since a team can get at most a single letter balloon for any problem. And Xerxes College is also out of luck because there is no problem X in this example.

You've been wondering---what is the maximum number of teams that can proudly display their school's initials with "first-solver" balloons at the end of the contest?

입력

The first line of input contains two integers pp tt, where pp (1≤p≤261 \leq p \leq 26) is the number of problems in the contest, 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 8080 uppercase letters describing a school's initials. There is only one team from each school, but several schools may have the same initials.

출력

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

예제2

  1. 예제 1

    입력
    23 5
    WMU
    SI
    MI
    TTT
    XT
    
    예상 출력
    2
    
  2. 예제 2

    입력
    6 6
    ABC
    BDE
    ABE
    BF
    BF
    CEF
    
    예상 출력
    1