# -*- coding: utf-8 -*- """ No.561 東京と京都 https://yukicoder.me/problems/no/561 """ import sys from sys import stdin input = stdin.readline def solve(earnings, D): TOKYO, KYOTO = 0, 1 res = [[0, -D]] for t, k in earnings: tokyo_e = max(res[-1][TOKYO] + t, res[-1][KYOTO] + t - D) kyoto_e = max(res[-1][TOKYO] + k - D, res[-1][KYOTO] + k) res.append([tokyo_e, kyoto_e]) return max(res[-1][TOKYO], res[-1][KYOTO]) def main(args): N, D = map(int, input().split()) earnings = [] for _ in range(N): tokyo, kyoto = map(int, input().split()) earnings.append([tokyo, kyoto]) ans = solve(earnings, D) print(ans) if __name__ == '__main__': main(sys.argv[1:])