Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. 

Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!

Input

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, <image>) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively.

Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type mi, si (0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively. 

Output

Print the maximum total friendship factir that can be reached.

Examples

Input

4 5
75 5
0 100
150 20
75 1


Output

100


Input

5 100
0 7
11 32
99 10
46 8
87 54


Output

111

Note

In the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.

In the second sample test we can take all the friends.
5 9
0 98
2 1000000000
8 1000000000
5 999999999
3 989898989
 4 1
2 4
2 2
3 3
3 3
 3 1
801 10101
802 134509124
801 1
 5 6
5 11
10 11
11 11
12 11
100 1
 7 6
5 11
9 11
10 11
11 11
12 11
13 11
100 1
 3 3
4 15
0 17
9 11
 15 1234
2738 322313356
1160 970909702
2594 902749351
3126 324754476
3151 177963947
3424 396145897
5578 737768323
3423 687640543
381 848813098
1058 197211286
936 650181776
1025 776492538
3598 142176544
3595 680519527
1191 32199940
 5 1
5 9
2 10
8 5
18 12
1 1
 8 5
3 227589091
12 131068951
8 492784630
20 918918112
11 6972428
20 585402296
12 220234661
1 225083234
 5 10
8 90
1009 1000000
9 121
10 298
0 109092
 4 2
1 1
2 100
3 100
4 1
 4 2
10909234 9
10909236 8
10909237 10
10909235 98
 1 1000000000
15 12

3989899086 6 134509124 33 55 17 3634263641 12 1504320408 1000000 200 107 12
import javafx.util.Pair;

import java.io.*;
import java.util.*;
import java.util.function.Function;

public class Main {
    private final static InputReader ir = new InputReader(System.in);
    private final static OutputWriter ow = new OutputWriter(System.out);
    private final static int INF = Integer.MAX_VALUE;
    private final static int NINF = Integer.MIN_VALUE;
    private final static double PI = Math.PI;

    public static void main(String[] args) throws IOException {
        try {
            task();
        } finally {
            boolean exc = false;
            try {
                ir.close();
            } catch (IOException e) {
                e.printStackTrace();
                exc = true;
            }
            try {
                ow.close();
            } catch (IOException e) {
                e.printStackTrace();
                exc = true;
            }
            if (exc) System.exit(1);
        }
    }

    private static int lowerBound(int key, ArrayList<Pair<Integer, Integer>> list) {
        int lo = 0;
        int hi = list.size();

        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            int val = list.get(mid).getKey();
            if (val < key) {
                lo = mid + 1;
            } else if (val >= key) {
                if (mid - 1 < 0 || list.get(mid - 1).getKey() < key)
                    return mid;
                else hi = mid - 1;
            }
        }
        return -1;
    }

    private static int upperBound(int key, ArrayList<Pair<Integer, Integer>> list) {
        int lo = 0;
        int hi = list.size();

        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            int val = list.get(mid).getKey();
            if (val <= key) {
                if (mid + 1 >= list.size() || list.get(mid + 1).getKey() > key)
                    return mid;
                else lo = mid + 1;
            } else if (val > key) {
                hi = mid - 1;
            } else return mid;
        }
        return -1;
    }


    private static void task() throws IOException {
        int n = ir.nextInt(), d = ir.nextInt();
        ArrayList<Pair<Integer, Integer>> friends = new ArrayList<>(n);
        for (int i = 0; i < n; ++i) {
            friends.add(new Pair<>(ir.nextInt(), ir.nextInt()));
        }

        //friends.sort(Comparator.comparing(Pair::getValue));
        friends.sort(Comparator.comparing(Pair::getKey));
        long[] sum = new long[n];
        sum[0] = friends.get(0).getValue();

        for (int i = 1; i < n; ++i) {
            sum[i] = sum[i - 1] + friends.get(i).getValue();
        }

        long ans = 0;

        for (int i = 0; i < n; ++i) {
            int lo = friends.get(i).getKey();
            int hi = friends.get(i).getKey() + d - 1;

            //System.out.println(lo + " " + hi);

            int il = lowerBound(lo, friends);
            int ih = upperBound(hi, friends);

            //System.out.println(il + " " + ih);

            long s;
            if (il > 0)
                s = sum[ih] - sum[il - 1];
            else s = sum[ih];

            //System.out.println(s);

            if (s > ans) ans = s;
        }

        ow.print(ans);

        //friends.forEach(System.out::println);
        /*
        long sum = 0;
        long ans = 0;
        int imin = 0;
        int imax = 0;
        for (int l = 0; l < n;) {
            //System.out.println("l " + l);
            boolean go = true;
            for (int r = l; r < n && go;) {
                //System.out.println("r " + r);
                Pair<Integer, Integer>
                        pair = friends.get(r),
                        min = friends.get(imin),
                        max = friends.get(imax);

                if (pair.getKey() > max.getKey() - d &&
                        pair.getKey() < min.getKey() + d) {
                    sum += pair.getValue();
                    if (friends.get(r).getKey() < min.getKey()) {
                        imin = r;
                    }
                    if (friends.get(r).getKey() > max.getKey()) {
                        imax = r;
                    }
                    r++;
                }
                else {
                    if (sum > ans) ans = sum;
                    sum = 0;
                    if (pair.getKey() <= max.getKey() - d) {
                        l = imax + 1;
                    } else if (pair.getKey() >= min.getKey() + d) {
                        l = imin + 1;
                    } else {
                        assert false : "error";
                    }
                    go = false;
                    imax = imin = l;
                }

            }
        }
        if (sum > ans) ans = sum;
        ow.print(ans);
        */
    }

    private static int max(int... objects) {
        if (objects.length == 0)
            throw new IllegalArgumentException("objects.length == 0");
        int max = objects[0];
        for (int i = 1; i < objects.length; ++i) {
            if (max < objects[i])
                max = objects[i];
        }
        return max;
    }

    private static int min(int... objects) {
        if (objects.length == 0)
            throw new IllegalArgumentException("objects.length == 0");
        int min = objects[0];
        for (int i = 1; i < objects.length; ++i) {
            if (min > objects[i])
                min = objects[i];
        }
        return min;
    }

    private static long pow(int x, int n) {
        if (x == 0) return 0;
        if (x == 1 || n == 0) return 1;
        if (x == 2) return x << (n - 1);
        if (n == 1) return x;
        long t = pow(x, n / 2);
        if (n % 2 == 0) return t * t;
        else return t * t * x;
    }

    private static double pow(double x, int n) {
        if (x == 0.0) return 0;
        if (x == 1.0 || n == 0) return 1;
        if (n == 1) return x;
        double t = pow(x, n / 2);
        if (n % 2 == 0) return t * t;
        else return t * t * x;
    }

    private static int abs(int a) {
        return (a >= 0 ? a : -a);
    }
}

class SQRTDecomposition {
    private int[] array;
    private int len;
    private int[] max;
    private int[] min;

    public SQRTDecomposition(int[] arr, boolean useIt) {
        if (useIt)
            array = arr;
        else {
            array = new int[arr.length];
            System.arraycopy(arr, 0, array, 0, arr.length);
        }
        len = (int) Math.sqrt(array.length) + 1;
        max = new int[len];
        min = new int[len];
        for (int i = 0; i < array.length; ++i) {
            max[i / len] = min[i / len] = array[i];
        }
        for (int i = 0; i < array.length; ++i) {
            max[i / len] = Math.max(max[i / len], array[i]);
            min[i / len] = Math.min(min[i / len], array[i]);
        }
    }

    public int get(int i) {
        if (i <= 0 || i >= array.length)
            throw new IndexOutOfBoundsException("Index: " + i);
        return array[i];
    }

    public int length() {
        return array.length;
    }

    public int max(int l, int r) {
        int cl = l / len, cr = r / len;
        int m = array[l];
        if (cl == cr) {
            for (int i = l; i <= r; ++i) {
                if (array[i] > m) m = array[i];
            }
        } else {
            for (int i = l, end = (cl + 1) * len - 1; i <= end; ++i)
                if (array[i] > m) m = array[i];
            for (int i = cl + 1; i <= cr - 1; ++i)
                if (max[i] > m) m = max[i];
            for (int i = cr * len; i <= r; ++i)
                if (array[i] > m) m = array[i];
        }
        return m;
    }

    public int min(int l, int r) {
        int cl = l / len, cr = r / len;
        int m = array[l];
        if (cl == cr) {
            for (int i = l; i <= r; ++i) {
                if (array[i] < m) m = array[i];
            }
        } else {
            for (int i = l, end = (cl + 1) * len - 1; i <= end; ++i)
                if (array[i] < m) m = array[i];
            for (int i = cl + 1; i <= cr - 1; ++i)
                if (min[i] < m) m = min[i];
            for (int i = cr * len; i <= r; ++i)
                if (array[i] < m) m = array[i];
        }
        return m;
    }
}

class InputReader implements AutoCloseable {
    private final InputStream in;
    private int capacity;
    private byte[] buffer;
    private int len = 0;
    private int cur = 0;

    public InputReader(InputStream stream) {
        this(stream, 100_000);
    }

    public InputReader(InputStream stream, int capacity) {
        this.in = stream;
        this.capacity = capacity;
        buffer = new byte[capacity];
    }

    private boolean update() {
        if (cur >= len) {
            try {
                cur = 0;
                len = in.read(buffer, 0, capacity);
                if (len <= 0)
                    return false;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    private int read() {
        if (update())
            return buffer[cur++];
        else return -1;
    }

    public boolean isEmpty() {
        return !update();
    }

    private boolean isSpace(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == ' ';
    }

    private boolean isEscape(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == -1;
    }

    private int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public int nextInt() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    public int[] getAllInts() {
        List<Integer> list = new LinkedList<>();
        while (true) {
            try {
                int t = nextInt();
                list.add(t);
            } catch (InputMismatchException e) {
                break;
            }
        }
        int[] a = new int[list.size()];
        Iterator<Integer> it = list.iterator();
        for (int i = 0; it.hasNext(); ++i)
            a[i] = it.next();
        return a;
    }

    public int[] getIntArray1D(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; ++i) {
            array[i] = nextInt();
        }
        return array;
    }

    public int[][] getIntArray2D(int n, int m) {
        int[][] array = new int[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                array[i][j] = nextInt();
        }
        return array;
    }

    public long nextLong() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    public long[] getAllLongs() {
        List<Long> list = new LinkedList<>();
        while (true) {
            try {
                long t = nextLong();
                list.add(t);
            } catch (InputMismatchException e) {
                break;
            }
        }
        long[] a = new long[list.size()];
        Iterator<Long> it = list.iterator();
        for (int i = 0; it.hasNext(); ++i)
            a[i] = it.next();
        return a;
    }

    public long[] getLongArray1D(int n) {
        long[] array = new long[n];
        for (int i = 0; i < n; ++i) {
            array[i] = nextLong();
        }
        return array;
    }

    public long[][] getLongArray2D(int n, int m) {
        long[][] array = new long[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                array[i][j] = nextLong();
        }
        return array;
    }

    public int nextChar() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        return c;
    }

    public String nextLine(int initialCapacity) {
        StringBuilder res = new StringBuilder(initialCapacity);
        int c = readSkipSpace();
        do {
            res.append((char) (c));
            c = read();
        } while (!isEscape(c));
        return res.toString();
    }

    @Override
    public void close() throws IOException {
        in.close();
    }
}

class OutputWriter implements Flushable, AutoCloseable {
    private byte[] buf;
    private final int capacity;
    private int count;
    private OutputStream out;

    public OutputWriter(OutputStream stream) {
        this(stream, 10_000);
    }

    public OutputWriter(OutputStream stream, int capacity) {
        if (capacity < 0)
            throw new IllegalArgumentException("capacity < 0");
        out = stream;
        this.capacity = capacity;
        if (capacity != 0) {
            buf = new byte[capacity];
        }
    }

    public void write(int b) throws IOException {
        if (capacity != 0) {
            if (count >= capacity)
                flushBuffer();
            buf[count++] = (byte) b;
        } else {
            out.write(b);
        }
    }

    public void write(byte[] bytes, int off, int len) throws IOException {
        if (capacity != 0) {
            if (len >= capacity) {
                flushBuffer();
                out.write(bytes, off, len);
                return;
            }
            if (len > capacity - count)
                flushBuffer();
            System.arraycopy(bytes, off, buf, count, len);
            count += len;
        } else out.write(bytes, off, len);
    }

    public void write(byte[] bytes) throws IOException {
        write(bytes, 0, bytes.length);
    }

    public void println() throws IOException {
        print("\n");
    }

    public void print(Object object) throws IOException {
        write(String.valueOf(object).getBytes());
    }

    public void println(Object object) throws IOException {
        print(object);
        println();
    }

    public void print(int... ints) throws IOException {
        print(" ", ints);
    }

    public void println(int... ints) throws IOException {
        print(ints);
        println();
    }

    public void println(String separator, int... ints) throws IOException {
        print(separator, ints);
        println();
    }

    public void print(String separator, int... ints) throws IOException {
        if (ints.length == 0) throw new IllegalArgumentException("ints.length == 0");
        for (int i = 0; i < ints.length; ++i) {
            if (i != 0) print(separator);
            print(ints[i]);
        }
    }

    private void flushBuffer() throws IOException {
        if (count > 0) {
            out.write(buf, 0, count);
            count = 0;
        }
    }

    @Override
    public void flush() throws IOException {
        flushBuffer();
        out.flush();
    }

    @Override
    public void close() throws IOException {
        flush();
        out.close();
    }
}
/*
class InputReader implements AutoCloseable {
    private final InputStream in;
    private int capacity;
    private byte[] buffer;
    private int len = 0;
    private int cur = 0;

    public InputReader(InputStream stream) {
        this(stream, 100_000);
    }

    public InputReader(InputStream stream, int capacity) {
        this.in = stream;
        this.capacity = capacity;
        buffer = new byte[capacity];
    }

    private int read() {
        if (cur >= len) {
            try {
                cur = 0;
                len = in.read(buffer, 0, capacity);
                if (len <= 0)
                    return -1;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return buffer[cur++];
    }

    private boolean isSpace(int c) {
        return c == ' ' || isEscape(c);
    }

    private boolean isEscape(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == -1;
    }

    private int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    int nextInt() {
        int c = readSkipSpace();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    public long nextLong() {
        int c = readSkipSpace();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    int nextChar() {
        return readSkipSpace();
    }

    String nextLine(int initialCapacity) {
        StringBuilder res = new StringBuilder(initialCapacity);
        int c = readSkipSpace();
        do {
            res.append((char) (c));
            c = read();
        } while (!isEscape(c));
        return res.toString();
    }

    @Override
    public void close() throws IOException {
        in.close();
    }
}

class OutputWriter implements Flushable, AutoCloseable {
    private byte[] buf;
    private int capacity;
    private int count;
    private OutputStream out;

    public OutputWriter(OutputStream stream) {
        out = stream;
        capacity = 10_000;
        buf = new byte[capacity];
    }

    public OutputWriter(OutputStream stream, int capacity) {
        if (capacity <= 0)
            throw new IllegalArgumentException("capacity <= 0");
        out = stream;
        this.capacity = capacity;
        buf = new byte[capacity];
    }

    public void write(int b) throws IOException {
        if (count >= buf.length)
            flushBuffer();
        buf[count++] = (byte) b;
    }

    public void write(byte[] bytes, int off, int len) throws IOException {
        if (len >= buf.length) {
            flushBuffer();
            out.write(bytes, off, len);
            return;
        }
        if (len > buf.length - count)
            flushBuffer();
        System.arraycopy(bytes, off, buf, count, len);
        count += len;
    }

    public void write(byte[] bytes) throws IOException {
        write(bytes, 0, bytes.length);
    }

    public void print(String str) throws IOException {
        write(str.getBytes());
    }

    public void println() throws IOException {
        print("\n");
    }

    public void print(Object object) throws IOException {
        print(object.toString());
    }

    public void println(Object object) throws IOException {
        print(object.toString());
        println();
    }

    public void print(int... ints) throws IOException {
        print(" ", ints);
    }

    public void println(int... ints) throws IOException {
        print(ints);
        println();
    }

    public void println(String separator, int... ints) throws IOException {
        print(separator, ints);
        println();
    }

    public void print(String separator, int... ints) throws IOException {
        if (ints.length == 0) throw new IllegalArgumentException("ints.length == 0");
        for (int i = 0; i < ints.length; ++i) {
            if (i != 0) print(separator);
            print(ints[i]);
        }
    }

    private void flushBuffer() throws IOException {
        if (count > 0) {
            out.write(buf, 0, count);
            count = 0;
        }
    }

    @Override
    public void flush() throws IOException {
        flushBuffer();
        out.flush();
    }

    @Override
    public void close() throws IOException {
        flush();
        out.close();
    }
}

*/


