N,M = map(int,input().split()) A = [[0 for _ in range(M+1)]] for _ in range(M): A.append([0]+list(map(int,input().split()))) dp = [[0 for _ in range(M+1)] for _ in range(M+1)] dp[1][1] = A[1][1] for j in range(1,M+1): dp[1][j] = dp[1][j-1]+A[1][j] dp[j][1] = dp[j-1][1]+A[j][1] for i in range(2,M+1): for j in range(2,M+1): dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+A[i][j] for _ in range(M): y,x = map(int,input().split()) ans = 0 for i in range(1,y+1): for j in range(1,x+1): for k in range(y,M+1): for l in range(x,M+1): area = dp[k][l]-dp[k][j-1]-dp[i-1][l]+dp[i-1][j-1] if area==0: ans += 1 print(ans)