def calc_sum(ax, ay, bx, by, S): return S[bx][by] - S[bx][ay] - S[ax][by] + S[ax][ay] N, M = map(int, input().split()) S = [[0] * (M + 1) for i in range(M + 1)] A = [] for i in range(M): A.append(list(map(int, input().split()))) for i in range(1, M + 1): for j in range(1, M + 1): S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + A[i - 1][j - 1] for i in range(N): x, y = map(int, input().split()) x, y = x - 1, y - 1 ans = 0 for a in range(x + 1): for b in range(y + 1): for c in range(x + 1, M + 1): for d in range(y + 1, M + 1): if calc_sum(a, b, c, d, S) == 0: ans += 1 print(ans)