n, d = [ int(v) for v in input().split() ] salalyinTokyo, salalyinKyoto = [ int(v) for v in input().split() ] WorkinTokyomax, WorkinKyotomax = salalyinTokyo, salalyinKyoto - d for i in range(1,n): salalyinTokyo, salalyinKyoto = [ int(v) for v in input().split() ] WorkinTokyomax, WorkinKyotomax = max(WorkinTokyomax + salalyinTokyo, WorkinKyotomax + salalyinTokyo - d), max(WorkinTokyomax + salalyinKyoto - d, WorkinKyotomax + salalyinKyoto) print(max(WorkinTokyomax, WorkinKyotomax))