D_C = input().split() Tokyo = True Total = 0 Tokyo_money = 0 Kyoto_money = 0-int(D_C[1]) for i in range(int(D_C[0])): money = input().split() Tokyo_money += int(money[0]) Kyoto_money += int(money[1]) if Tokyo: if int(money[0]) <= int(money[1])-int(D_C[1]): Tokyo = False Total += int(money[1])-int(D_C[1]) else: Total += int(money[0]) else: if int(money[1]) <= int(money[0])-int(D_C[1]): Tokyo = True Total += int(money[0])-int(D_C[1]) else: Total += int(money[1]) if Kyoto_money > Total: Total = Kyoto_money elif Tokyo_money > Total: Total = Tokyo_money print(Total)