n, d = map(int, input().split()) t, k = map(int, input().split()) dpt = t dpk = k-d for i in range(1, n): t, k = map(int, input().split()) ndpt = max(dpt+t, dpk-d+t) ndpk = max(dpk+k, dpt-d+k) dpt = ndpt dpk = ndpk print(max(dpt, dpk))