def shunyu(N, D, TK): '''shunyu()はリスト。 idx=0はN日目に東京で働いた場合の最大収入 idx=1はN日目に京都で働いた場合の最大収入''' if N == 1: result = [TK[0][0], TK[0][1] - D] return result bef_shunyu = shunyu(N - 1, D, TK) t_li = [0, 0] k_li = [0, 0] t_li[0] = bef_shunyu[0] + TK[N - 1][0] t_li[1] = bef_shunyu[1] + TK[N - 1][0] - D k_li[0] = bef_shunyu[0] + TK[N - 1][1] - D k_li[1] = bef_shunyu[1] + TK[N - 1][1] result = [max(t_li), max(k_li)] return result def hantei(N, D, TK): li = shunyu(N, D, TK) return max(li) def main(): N, D = map(int, input().split()) TK = [[] for x in range(N)] for n in range(N): TK[n] = list(map(int, input().split())) print(hantei(N, D, TK)) if __name__ == '__main__': main()