N, D = map(int, input().split()) t, k = 0, -10**18 for i in range(N): T, K = map(int, input().split()) nt = max(t + T, k + T - D) nk = max(k + K, t + K - D) t, k = nt, nk print(max(t, k))