import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### import numpy as np import math from math import floor def binom(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) h, w = na() a = [na() for i in range(h)] a = np.array(a) b = [na() for i in range(h)] b = np.array(b) #print(a) #print(b) ab = np.dot(a, b.T) #print(ab) ans = 0 for i in range(1, 1 << h): pc = bin(i).count('1') A = np.array([[ab[j][k] for k in range(w) if i >> k & 1] for j in range(h) if i >> j & 1]) #print(bin(i), A, int(np.linalg.det(A))) ans += floor(0.5+np.linalg.det(A)) * binom(h-1, pc-1) print(ans)