logo AlgoBeat OnlineJudge
登录 注册

#214565. [2019 KAIST RUN Fall] 6789

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Jaehyun likes digits. Among the 10 digits, 6, 7, 8, and 9 are his favorite. Therefore, he made a special card set consisting of only 6, 7, 8 and 9.

Currently, Jaehyun has cards. Jaehyun wants to make a magical by matrix of cards. Each row of the matrix should contain cards. He already arranged his cards in a shape of by matrix.

:::align{center}

Figure 1. Initial state, not point symmetric. :::

To be a magic matrix, the matrix must be point symmetrical: Rotating the matrix 180 degrees results in the same original matrix. For example, 8 is point symmetrical with itself, and 6 and 9 are point symmetrical with each other. Jaehyun doesn't want to switch the position of the cards, so his goal is to make the matrix point symmetrical by only rotating the cards in their original positions.

:::align{center}

Figure 2. After rotating two cards, they are point symmetric. :::

Find the minimum number of cards you have to turn to make a magic matrix.

输入格式

The first line contains two integers, and . ()

Each of the next lines contains a string of characters which denotes the numbers written in each card. It is guaranteed that each character is one of , , , or .

输出格式

Print the minimum number of cards you have to turn to make a magic matrix in the first line. If it is not possible to make a magic matrix, print . (without quotes)

样例

样例输入 1

2 3
676
679

样例输出 1

2

样例输入 2

3 3
888
888
888

样例输出 2

0

样例输入 3

1 1
7

样例输出 3

-1