human
Can you provide a Python code to determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all given the following:
A binary matrix is called good if every even length square sub-matrix has an odd number of ones. 

Given a binary matrix a consisting of n rows and m columns, determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all. 

All the terms above have their usual meanings — refer to the Notes section for their formal definitions. 

Input

The first line of input contains two integers n and m (1 ≤ n ≤ m ≤ 10^6 and n⋅ m ≤ 10^6) — the number of rows and columns in a, respectively. 

The following n lines each contain m characters, each of which is one of 0 and 1. If the j-th character on the i-th line is 1, then a_{i,j} = 1. Similarly, if the j-th character on the i-th line is 0, then a_{i,j} = 0.

Output

Output the minimum number of cells you need to change to make a good, or output -1 if it's not possible at all.

Examples

Input

3 3
101
001
110

Output

2

Input

7 15
000100001010010
100111010110001
101101111100100
010000111111010
111010010100001
000011001111101
111111011010011

Output

-1

Note

In the first case, changing a_{1,1} to 0 and a_{2,2} to 1 is enough. 

You can verify that there is no way to make the matrix in the second case good. 

Some definitions — 

  * A binary matrix is one in which every element is either 1 or 0. 
  * A sub-matrix is described by 4 parameters — r_1, r_2, c_1, and c_2.
here, 1 ≤ r_1 ≤ r_2 ≤ n and 1 ≤ c_1 ≤ c_2 ≤ m. 
  * This sub-matrix contains all elements a_{i,j} that satisfy both r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2. 
  * A sub-matrix is, further, called an even length square if r_2-r_1 = c_2-c_1 and r_2-r_1+1 is divisible by 2. 
The above is tricky. Write me a correct solution in PYTHON3.
assistant
#Here is Python code to determine the minimum number of cells you need to change to make it good, or report that there is no way to make it good at all.

import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------------------
 
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def print_list(l):
	print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import...