N,D=map(int,input().split()) B="T" ans=0 for i in range(N): T,K=map(int,input().split()) if B=="T": ans=max(ans+T,ans+K-D) if T