import sys, time, random, heapq from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 #https://tjkendev.github.io/procon-library/python/convex_hull_trick/deque.html deq = deque() def check(f1, f2, f3): return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0]) def f(f1, x): return f1[0]*x + f1[1] # add f_i(x) = a*x + b def add_line(a, b): f1 = (a, b) while len(deq) >= 2 and check(deq[-2], deq[-1], f1): deq.pop() deq.append(f1) # min f_i(x) def query(x): while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x): deq.popleft() return f(deq[0], x) n, m = mi() AD = [li() for _ in range(n)] plus = [] minus = [] for a, d in AD: if d > 0: plus.append((a, d)) else: minus.append((a, d)) p = [-inf] * (m + 1) p[0] = 0 for a, d in plus: add_line(-d, -2 * a + d) if plus: for i in range(1, m + 1): p[i] = -query(i) * i // 2 q = [-inf] * (m + 1) q[0] = 0 H = [] for a, d in minus: heapq.heappush(H, (-a, d)) for i in range(1, m + 1): a, d = heapq.heappop(H) a = -a q[i] = q[i - 1] + a heapq.heappush(H, (-(a + d), d)) ans = -inf maxi = -1 for i in range(0, m + 1): if ans <= p[i] + q[m - i]: ans = max(ans, p[i] + q[m - i]) maxi = i print(ans) print(maxi, file=sys.stderr)