N, K = map(int, input().split()) dp = [0] * (N+1) data = [] for i in range(N): a, m = map(int, input().split()) data.append((a, m)) B = list(map(lambda x:int(x)-1, input().split())) if i: dp[i] = dp[i-1] for b in B: aa, mm = data[b] dp[i] = max(dp[i], dp[b]+a-aa) print(max(dp))