시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 2048 MB50231943.182%

문제

A common activity for students during a lecture is playing BINGO. However, they don't play the regular boring game with the numbered balls. Instead, their BINGO sheets contain in every square an event that might (or might not) happen during a lecture, and once the event happens, this square can be crossed off.

Since you'd also like to pay attention during the lecture while playing this game, you decide to build a program that automatically plays BINGO for you. Given a BINGO sheet with a grid of $n \times n$ squares, and a list of events that happen during the lecture, how many events will pass before you can shout "BINGO!"?

Note that you may shout "BINGO!" whenever you crossed off all squares in any row, column, or diagonal of the grid. The middle square in your grid can always be crossed off for free.

입력

One line containing two integers: one odd integer $n$, with $1 \leq n \leq 10^3$, and one integer $m$, with $0 \leq m \leq 10^6$. $n$ lines, each containing $n$ space-separated events. Event names consist of only alphanumeric characters, and every event only happens at most once. $m$ lines, with on every line an event that happens during the lecture.

출력

One integer, indicating after how many events you can shout "BINGO!". If you cannot shout "BINGO!" during this lecture, output a sad smiley face: :-(

예제 입력 1

3 10
WordMispronounced LoudMic Gaming
Sleeping FreeLunch Latecomer
2MinutesSilence TeacherAngry Eating
MicBreaks
Sleeping
SlideshowContainsMistake
WordMispronounced
Gaming
PhoneRings
Eating
Latecomer
TeacherAngry
2MinutesSilence

예제 출력 1

7

예제 입력 2

3 5
EventA EventB EventC
EventD EventE EventF
EventG EventH EventI
EventJ
EventA
EventK
EventB
EventD

예제 출력 2

:-(