#!/usr/bin/python2 # -*- coding: utf-8 -*- # † from itertools import product from itertools import chain flatten = chain.from_iterable R, C = map(int, raw_input().split()) n = R * C A = [[0 for j in range(n)] for i in range(n)] # A[n][n] for r in xrange(R): for c in xrange(C): i = r * C + c for dr, dc in product([-1, 0, 1], repeat=2): nr = r + dr nc = c + dc if not (0 <= nr < R and 0 <= nc < C): continue ni = nr * C + nc A[ni][i] = 1 def add_rows(A, i, j): return [(A[i][k] + A[j][k]) % 2 for k in xrange(n)] def swap_rows(A, i, j): A[i], A[j] = A[j], A[i] mat = [map(int, raw_input().split()) for _ in xrange(R)] state = list(flatten(mat)) G = state[:] for c in xrange(n): for r in xrange(c, n): if A[r][c] == 1: swap_rows(A, r, c) swap_rows(state, r, c) for other in xrange(n): if other != c and A[other][c] == 1: A[other] = add_rows(A, other, c) state[other] ^= state[c] for i in xrange(R*C): if state[i]: r, c = divmod(i, C) for dr in [-1, 0, 1]: for dc in [-1, 0, 1]: nr = r + dr nc = c + dc if not (0 <= nr < R and 0 <= nc < C): continue G[nr*C+nc] = 1 - G[nr*C+nc] if any(x!=0 for x in G): print 'Impossible' exit(0) res = state.count(1) print res