// Arup Guha
// 3/24/2015
// Solution to 2014 March USACO Bronze Problem: The Lazy Cow

import java.util.*;
import java.io.*;

public class lazy {

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new FileReader("lazy.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int k = Integer.parseInt(tok.nextToken());

		// Read in food and sort.
		grass[] food = new grass[n];
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			int numGrass = Integer.parseInt(tok.nextToken());
			int x = Integer.parseInt(tok.nextToken());
			food[i] = new grass(x, numGrass);
		}
		Arrays.sort(food);
		stdin.close();

		// Set these...
		int best = 0, cur = 0, lowIndex = 0, highIndex = 0;

		// Sweep goes to the end.
		while (highIndex < n) {

			// Sweep forward.
			while (highIndex < n && food[lowIndex].x + 2*k  >= food[highIndex].x) {
				cur += food[highIndex].value;
				best = Math.max(best, cur);
				highIndex++;
			}

			// Done!
			if (highIndex == n) break;

			// Subtract this out, moving up lowIndex.
			cur -= food[lowIndex].value;
			lowIndex++;
		}

		// Write out the result.
		FileWriter fout = new FileWriter(new File("lazy.out"));
		fout.write(best+"\n");
		fout.close();
	}
}

class grass implements Comparable<grass> {

	public int x;
	public int value;

	public grass(int myX, int myValue) {
		x = myX;
		value = myValue;
	}

	// Just to get them in order of x.
	public int compareTo(grass other) {
		return this.x - other.x;
	}
}