import java.io.*;
import java.util.*;

public class Contest169ProblemA implements Runnable {

    void solve() throws NumberFormatException, IOException {
        int n = nextInt(), a = nextInt(), b = nextInt();

        ArrayList<Integer> tasks= new ArrayList<Integer>();

        for (int i = 0; i < n; ++i){
            tasks.add(nextInt());
        }
        Collections.sort(tasks);

        int l1 = tasks.get(b-1);
        int l2 = tasks.get(b);

        if (l2 - l1 >= 0){
            out.print(l2-l1);
        } else {
            out.print(l2-l1);
        }

    }

    StringTokenizer st;

    BufferedReader in;

    PrintWriter out;

    public static void main(String[] args) {

        new Thread(new Contest169ProblemA()).start();
    }

    public void run() {

        try {
            if (System.getProperty("ONLINE_JUDGE") != null) {
                in = new BufferedReader(new InputStreamReader(System.in));
            } else {
                in = new BufferedReader(new FileReader("input.txt"));
            }

            out = new PrintWriter(System.out);

            solve();

        } catch (Exception e) {

            e.printStackTrace();
            System.out.print(e);
            System.exit(9000);

        } finally {

            out.flush();

            out.close();

        }

    }

    //Получаем следующий токен

    String nextToken() throws IOException {

        while (st == null || !st.hasMoreTokens()) {

            st = new StringTokenizer(in.readLine());

        }

        return st.nextToken();

    }

    int nextInt() throws NumberFormatException, IOException {

        return Integer.parseInt(nextToken());

    }

    long nextLong() throws NumberFormatException, IOException {

        return Long.parseLong(nextToken());

    }

    double nextDouble() throws NumberFormatException, IOException {

        return Double.parseDouble(nextToken());

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[]parts = br.readLine().split("\\s+");
		int n = Integer.parseInt(parts[0]);
		int a = Integer.parseInt(parts[1]);
		int b = Integer.parseInt(parts[2]);
		parts = br.readLine().split("\\s+");
		int[]hard = new int[n];
		for(int i = 0; i < n; i++){
			hard[i] = Integer.parseInt(parts[i]);
		}
		Arrays.sort(hard);
		System.out.println(hard[b]-hard[b-1]);
	}
}


import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class A {

    int INF = 1 << 28;

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        long[] chores = new long[n];
        for(int i=0;i<n;i++) chores[i] = sc.nextLong();
        sort(chores);
        System.out.println(chores[b]-chores[b-1]);
    }

    public static void main(String[] args) {
        new A().run();
    }
}


import java.io.*;
import java.util.*;

/**
 * @author Vaibhav Mittal
 */

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int testCases = 1;
        Task solver = new Task();
        for (int i = 1; i <= testCases; ++i)
            solver.solve(in, out);

        out.close();
    }
}

class Task {
    public void solve(Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] complexity = new int[n];
        for (int i = 0; i < n; ++i)
            complexity[i] = in.nextInt();
        Arrays.sort(complexity);
        out.println(complexity[b] - complexity[b - 1]);
    }
}


import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        int[] h = new int[3000];

        for(int i = 0; i<n; i++)
            h[i] = in.nextInt();

        int l = 0, r = 1000000000, m = 0;
        int ansl = 0, ansr = 0;

        while(l<=r){
            m = (l+r)/2;

            int ca=0;

            for(int i = 0;i<n;i++)
                if (h[i]>m) ca++;

            if (ca == a) ansl=m;
            if (ca <= a) r=m-1; else l=m+1;
        }
        l = 0; r = 1000000000;
        while(l<=r){
            m = (l+r)/2;

            int ca=0;

            for(int i = 0;i<n;i++)
                if (h[i]>m) ca++;

            if (ca == a) ansr=m;
            if (ca < a) r=m-1; else l=m+1;
        }
        if (ansl == 0 || ansr==0) System.out.print(0); else
        System.out.print(ansr-ansl+1);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution {
    //<editor-fold desc="input parse" defaultstate="collapsed">

    private static StringTokenizer st;
    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    private static long nextLong() {
        return Long.parseLong(st.nextToken());
    }

    private static int nextInt() {
        return Integer.parseInt(st.nextToken());
    }

    private static double nextDouble() {
        return Double.parseDouble(st.nextToken());
    }

    private static short nextShort() {
        return Short.parseShort(st.nextToken());
    }

    private static byte nextByte() {
        return Byte.parseByte(st.nextToken());
    }

    private static void initTokenizer() throws Exception {
        st = new StringTokenizer(reader.readLine());
    }

    //</editor-fold>

    public static void main(String[] args) throws Exception {
        initTokenizer();

        int n = nextInt();
        int a = nextInt();
        int b = nextInt();

        int[] h = new int[n];

        initTokenizer();

        for (int i = 0; i < n; i++) {
            h[i] = nextInt();
        }

        Arrays.sort(h);

        System.out.print(h[b] - h[b - 1]);
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;

        st = new StringTokenizer(in.readLine());

        int n = Integer.parseInt(st.nextToken()),
            a = Integer.parseInt(st.nextToken()),
            b = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(in.readLine());

        ArrayList<Integer> A = new ArrayList<Integer>();

        for (int i = 0 ; i < n ; i++) {
            A.add(Integer.parseInt(st.nextToken()));
        }

        Collections.sort(A);

        System.out.println(A.get(b) - A.get(b - 1));
    }
}


import java.awt.Point;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class Start {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Start().run();
    }

    public static void mergeSort(int[] a) {
        mergeSort(a, 0, a.length - 1);
    }

    private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
        final int MAGIC_VALUE = 50;
        if (levtIndex < rightIndex) {
            if (rightIndex - levtIndex <= MAGIC_VALUE) {
                insertionSort(a, levtIndex, rightIndex);
            } else {
                int middleIndex = (levtIndex + rightIndex) / 2;
                mergeSort(a, levtIndex, middleIndex);
                mergeSort(a, middleIndex + 1, rightIndex);
                merge(a, levtIndex, middleIndex, rightIndex);
            }
        }
    }

    private static void merge(int[] a, int levtIndex, int middleIndex,
            int rightIndex) {
        int length1 = middleIndex - levtIndex + 1;
        int length2 = rightIndex - middleIndex;
        int[] levtArray = new int[length1];
        int[] rightArray = new int[length2];
        System.arraycopy(a, levtIndex, levtArray, 0, length1);
        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
        for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
            if (i == length1) {
                a[k] = rightArray[j++];
            } else if (j == length2) {
                a[k] = levtArray[i++];
            } else {
                a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
                        : rightArray[j++];
            }
        }
    }

    private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
        for (int i = levtIndex + 1; i <= rightIndex; i++) {
            int current = a[i];
            int j = i - 1;
            while (j >= levtIndex && a[j] > current) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = current;
        }
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class LoL implements Comparable<LoL> {
        int x;
        int y;

        public LoL(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(LoL arg0) {
            if (arg0.x == x) {
                return y - arg0.y;
            }
            return arg0.x - x;
        }

    }

    public void solve() throws IOException {

        int n =  readInt();
        int a = readInt()-1;
        int b = readInt()-1;
        int [] d = new int [n];
        for (int i = 0; i <n; i++){
            d[i] = readInt();
        }
        mergeSort(d);
        out.print(d[b+1]-d[b]);
    }
}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author codeKNIGHT
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n=in.nextInt(),a=in.nextInt(),b=in.nextInt(),i,c=0;
        int ar[]=new int[n];
        for(i=0;i<n;i++)
            ar[i]=in.nextInt();
        Arrays.sort(ar);
        out.println(ar[b]-ar[b-1]);
	}
}


import java.io.*;
import java.security.SecureRandom;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

    public void solve() throws Exception {

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        long h[] = new long[n];

        for (int i = 0;i < n; ++ i) {
            h[i] = sc.nextLong();
        }
        Arrays.sort(h);
        long l = h[n - a];
        long r = h[n - a - 1];
        out.println(l - r);
    }

    /*--------------------------------------------------------------*/

    static String filename = "";
    static boolean fromFile = false;

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    public static void main(String[] args) {
        new Thread(null, new Solution(), "", 1 << 25).start();
    }

    public void run() {
        try {
            init();
            solve();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            out.close();
        }
    }

    void init() throws Exception {
        if (fromFile) {
            in = new BufferedReader(new FileReader(filename+".in"));
            out = new PrintWriter(new FileWriter(filename+".out"));
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        sc = new FastScanner(in);
    }
}

class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }

        return strTok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

    public BigDecimal nextBigDecimal() throws IOException {
        return new BigDecimal(nextToken());
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class test {

    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int n = kb.nextInt();
        int a = kb.nextInt();
        int b = kb.nextInt();
        int array[] = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = kb.nextInt();
        }
        Arrays.sort(array);
        int k = 0;
        int t1 = 0;
        int t2 = 0;
        for (int i = 0; i < b; i++) {
            t1= array[i];
            if(i<n-1){
                t2=array[i+1];
                k=t2-t1;
            }
            else k=0;
        }
        System.out.println(k);

    }
}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author @zhendeaini6001
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] input = IOUtils.readIntArray(in, n);
        Arrays.sort(input);
        int x = input[b-1];
        int y = input[b];
        out.println(y - x);
    }
}

class IOUtils {

    public static int[] readIntArray(Scanner in, int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++)
            array[i] = in.nextInt();
        return array;
    }

    }


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class VkR2A{
    static BufferedReader br;
    public static void main(String args[])throws Exception{
        br=new BufferedReader(new InputStreamReader(System.in));

        int nm[] = toIntArray();
        int n = nm[0];
        int a = nm[1];
        int b = nm[2];
        nm=toIntArray();
        Arrays.sort(nm);
        int k=nm[b-1];
        int res=nm[b]-k;
        System.out.println(res);

    }

    /****************************************************************/
    public static int[] toIntArray()throws Exception{
       String str[]=br.readLine().split(" ");
       int k[]=new int[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Integer.parseInt(str[i]);
       }
       return k;
    }
    public static int toInt()throws Exception{
       return Integer.parseInt(br.readLine());
    }
    public static long[] toLongArray()throws Exception{
       String str[]=br.readLine().split(" ");
       long k[]=new long[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Long.parseLong(str[i]);
       }
       return k;
    }
    public static long toLong()throws Exception{
       return Long.parseLong(br.readLine());
    }
    public static double[] toDoubleArray()throws Exception{
       String str[]=br.readLine().split(" ");
       double k[]=new double[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Double.parseDouble(str[i]);
       }
       return k;
    }
    public static double toDouble()throws Exception{
       return Double.parseDouble(br.readLine());
    }
    public static String toStr()throws Exception{
       return br.readLine();
    }
    public static String[] toStrArray()throws Exception{
       String str[]=br.readLine().split(" ");
       return str;
    }
    /****************************************************************/

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        File _=new File("chores.in");
        BufferedReader br=_.exists()? new BufferedReader(new FileReader(_)):new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        String str;

        st=new StringTokenizer(br.readLine());
        int n,a,b;
        n=Integer.parseInt(st.nextToken());
        a=Integer.parseInt(st.nextToken());
        b=Integer.parseInt(st.nextToken());

        ArrayList<Integer> chores=new ArrayList<Integer>();
        int k;
        st=new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            k=Integer.parseInt(st.nextToken());
            chores.add(k);
        }
        Collections.sort(chores);

        System.out.println(chores.get(b)-chores.get(b-1));

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class problemA {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] hs = new int[n];
        for(int i = 0; i < n; i++){
            hs[i] = sc.nextInt();
        }
        Arrays.sort(hs);
        System.out.println(hs[b]-hs[b-1]);
    }
}


import sun.reflect.generics.tree.Tree;

import java.io.*;
import java.util.*;

public class A2 {
	static Scanner in; static int next() throws Exception {return in.nextInt();};
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;
	static PrintWriter out;

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

        int n = next(), a = next(), b = next();
        int h[] = new int[n];

        for (int i = 0;i < n;i++) h[i] = next();

        Arrays.sort(h);

        int res = h[b] - h[b-1];

        out.println(res);

        out.println();
		out.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ProblemA {

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        String[] data = s.readLine().split(" ");
        int n =  Integer.valueOf(data[0]);
        int a =  Integer.valueOf(data[1]);
        int b =  Integer.valueOf(data[2]);

        long[] h = new long[n];
        String[] line = s.readLine().split(" ");
        for (int i = 0 ; i < n ; i++) {
            h[i] = Integer.valueOf(line[i]);
        }
        Arrays.sort(h);

        System.out.println(h[b] - h[b-1]);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.InputMismatchException;

public class R2_D2_A {
    public static void main(String[] args) {
        // BufferedReader in = new BufferedReader(new
        // InputStreamReader(System.in));
        InputReader in = new InputReader(System.in);
        int n = in.readInt();
        int a = in.readInt();
        int b = in.readInt();
        Integer[] inp = new Integer[n];
        for (int i = 0; i < inp.length; i++) {
            inp[i] = in.readInt();
        }
        Arrays.sort(inp);
        int petya = inp[inp.length-a];
        int next = inp[inp.length-a-1];
        int diff = petya - next;
        System.out.println(diff);
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1000];
        private int curChar, numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        private String readLine0() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines)
                return readLine();
            else
                return readLine0();
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Train_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int [] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i]  = sc.nextInt();
        }
        Arrays.sort(h);
        System.out.println(h[n-a] - h[b-1]);
    }
}


import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
   private static IO io;

   public static void main(String[] args) throws IOException {
       new Main().run();
   }

   private void run() throws IOException {
       io = new IO(System.getProperty("ONLINE_JUDGE")!=null);
       solve();
       io.flush();
   }

   private void solve() throws IOException {
       int n = io.nI(), a = io.nI(), b = io.nI(), h[] = new int[n], i;
       for(i = 0; i<n; i++)h[i] = io.nI(); Arrays.sort(h);
       io.wln(h[b]-h[b-1]);
   }//2.2250738585072012e-308

   private int gcd(int a, int b) {
       while(b>0) b^=a^=b^=a%=b;
       return a;
   }

   @SuppressWarnings("unused")
   private class IO{
       StreamTokenizer in; PrintWriter out; BufferedReader br; Reader reader; Writer writer;
       public IO(boolean oj) throws IOException{
           Locale.setDefault(Locale.US);
           reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
           writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
           br = new BufferedReader(reader);
           in = new StreamTokenizer(br);
           out = new PrintWriter(writer);
       }
       public void wln(){out.println();}
       public void wln(int arg){out.println(arg);}
       public void wln(long arg){out.println(arg);}
       public void wln(double arg){out.println(arg);}
       public void wln(String arg){out.println(arg);}
       public void wln(boolean arg){out.println(arg);}
       public void wln(char arg){out.println(arg);}
       public void wln(float arg){out.println(arg);}
       public void wln(Object arg){out.println(arg);}
       public void w(int arg){out.print(arg);}
       public void w(long arg){out.print(arg);}
       public void w(double arg){out.print(arg);}
       public void w(String arg){out.print(arg);}
       public void w(boolean arg){out.print(arg);}
       public void w(char arg){out.print(arg);}
       public void w(float arg){out.print(arg);}
       public void w(Object arg){out.print(arg);}
       public void wf(String format, Object...args){out.printf(format, args);}
       public void flush(){out.flush();}
       public int nI() throws IOException {in.nextToken(); return(int)in.nval;}
       public long nL() throws IOException {in.nextToken(); return(long)in.nval;}
       public String nS() throws IOException {in.nextToken(); return in.sval;}
       public double nD() throws IOException {in.nextToken(); return in.nval;}
       public float nF() throws IOException {in.nextToken(); return (float)in.nval;}
       public void wc(char...a){for(char c : a){in.ordinaryChar(c);in.wordChars(c, c);}}
       public void wc(char c1, char c2){in.ordinaryChars(c1, c2); in.wordChars(c1, c2);}
   }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class SolA {

	private static InputReader in;
	private static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		run();
		out.close();
	}

	public static void run() {
		int n = in.readInt();
		int a = in.readInt();
		int b = in.readInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = - in.readInt();
		}
		Arrays.sort(h);

		int base = -h[a-1];
		int base1 = -h[a];
		out.print(-(base1 - base));

	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

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

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Solver {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public long result = 0;
    public int k = 0;

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        Solver solver = new Solver();
        solver.open();
        solver.solve();
        solver.close();
    }

    public void open() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    public void solve() throws NumberFormatException, IOException {
        int n = nextInt();
        int a = nextInt();
        int b = nextInt();

        int[] ar = new int[n];

        for(int i=0;i<n;i++){
            ar[i] = nextInt();
        }

        Arrays.sort(ar);

        out.println(ar[b]-ar[b-1]);
    }

    public void close() {
        out.flush();
        out.close();
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++)
            ar[i] = in.nextInt();
        Arrays.sort(ar);
        int x1 = ar[b-1];
        int x2 = ar[b];
        System.out.println(x2-x1);
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class CF_Chores {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int a = s.nextInt();
        int b = s.nextInt();

        long ar[] = new long[n];
        for (int i = 0; i < n; i++) {
            ar[i]=s.nextLong();
        }
        Arrays.sort(ar);

        long ret = 0;
//      System.out.println(Arrays.toString(ar));
        if(ar[b]==ar[b-1])
            System.out.println("0");
        else {
            ret = ar[b]-ar[b-1];
            System.out.println(ret);
        }

    }

}


import java.util.*;
import java.math.*;
import java.io.*;
public class Main
	{
	public static void main(String args[])	throws IOException
		{
		Scanner c=new Scanner(System.in);
		int n=c.nextInt();
		int a=c.nextInt();		//higher
		int b=c.nextInt();		//lower
		int C[]=new int[n];
		for(int i=0;i<n;i++)
			C[i]=c.nextInt();
		Arrays.sort(C);
		//System.out.println(Arrays.toString(C));
		int petya=C[n-a];
		System.out.println((C[n-a]-C[n-a-1]));
		}
	}

//must declare new classes here


import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}

	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}

	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}

	long nl() throws IOException
	{
		return Long.parseLong(ns());
	}

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

	String ns() throws IOException
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;
	int n,a,b;
	long arr[];

	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			if(!input())
				break;
			solve();
		}
	}

	void solve() throws IOException
	{
		Arrays.sort(arr);
		long x1 = arr[b-1];
		long x2 = arr[b];

		System.out.println(x2-x1);
	}

	boolean input() throws IOException
	{
		n = ni();
		a = ni();
		b = ni();
		arr = new long[n];
		for(int i = 0;i<n;i++)
		{
			arr[i] = nl();
		}
		return true;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        if (ar[b-1] == ar[b ]) {
            System.out.println(0);
        } else {
            System.out.println(ar[b ] - ar[b-1]);
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Solution
{
    public static void main(String[] args) throws IOException
    {
        new Solution().run();
    }
    StreamTokenizer in;
    Scanner ins;
    PrintWriter out;

    int nextInt() throws IOException
    {
        in.nextToken();
        return (int)in.nval;
    }

    void run() throws IOException
    {

        if(System.getProperty("ONLINE_JUDGE")!=null)
        {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            ins = new Scanner(System.in);
            out = new PrintWriter(System.out);
        }
        else
        {
            in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
            ins = new Scanner(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        }
        int n = nextInt(),a = nextInt(),b = nextInt();
        b--;
        int [] A = new int[n];
        for(int i = 0; i < n ;i++)
        {
            A[i] = nextInt();
        }
        Arrays.sort(A);
        if(A[b] == A[b+1])
            out.print(0);
        else
            out.print(A[b+1]- A[b]);
        out.close();
    }

    class Team implements Comparable
    {
        public int p,t;
        public int compareTo(Object obj)
        {
            Team a = (Team) obj;
            if(p>a.p || p==a.p && t<a.t)
                return -1;
            else
                if(p==a.p && t==a.t)
                    return 0;
                else
                    return 1;
        }

    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        int x[] = new int[n];
        for (int i=0; i<n; i++) x[i]=input.nextInt();
        Arrays.sort(x);
        int y[] = new int[n];
        for (int i=0; i<n; i++) y[i]=x[n-i-1];
        System.out.println(y[a-1]-y[a]);
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
public class A {
	@SuppressWarnings("unchecked")
	private static void solve() throws IOException {
		ArrayList<Num> c = new ArrayList<Num>();
		n = nextInt();
		a = nextInt();
		b = nextInt();
		for(int i = 0;  i < n; i++) {
			int next = nextInt();
			boolean found = false;
			for(int j = 0; j < c.size(); j++) {
				if(c.get(j).num == next) {
					c.get(j).freq++;
					found = true;
					break;
				}
			}
			if(!found)
				c.add(new Num(next));
		}
		Collections.sort(c);
		int below = 0;
		int above = n;
		boolean f = false;
		for(int i = 0; i < c.size(); i++) {
			below += c.get(i).freq;
			above -= c.get(i).freq;
			if(below == b && above == a) {
				if(i == c.size())
					break;
				System.out.println(c.get(i+1).num - c.get(i).num);
				f = true;
				break;
			}
		}
		if(!f)
			System.out.println(0);
	}

	static int n;
	static int a;
	static int b;
	public static void main(String[] args) {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	static String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}
class Num implements Comparable<Num> {
	int num;
	int freq;
	Num(int n) {
		num = n;
		freq = 1;
	}
	public int compareTo(Num other) {
		return this.num - other.num;
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		A solver = new A();
		solver.solve(1, in, out);
		out.close();
	}
}

class A {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.readInt();
        int a = in.readInt();
        int b = in.readInt();
        int[] hs = new int[n];
        for (int i=0;i<n;i++){
            hs[i]=in.readInt();
        }
        Arrays.sort(hs);
        out.println(hs[b]-hs[b-1]);
	}
}

class InputReader {
    BufferedReader in;

    public InputReader(InputStream stream) {
        in = new BufferedReader(new InputStreamReader(stream));
    }

    public int skipSpace() {
        int c;
        try {
            while (true) {
                c = in.read();
                if (c < 0) {
                    throw new InputMismatchException();
                }
                if (c > 32) {
                    break;
                }
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return c;
    }

    public int readInt() {
        int res = 0;
        boolean sign = false;
        int c = skipSpace();
        try {
            if (c == '-') {
                sign = true;
                c = in.read();
            }
            while (true) {
                if (c >= '0' && c <= '9') {
                    res = res * 10 + c - '0';
                } else {
                    throw new InputMismatchException();
                }
                c = in.read();
                if (c <= 32) {
                    break;
                }
            }
            if (sign) {
                res = -res;
            }
            return res;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    }


import java.io.*;
import java.util.*;

public class A
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	String FInput="";

	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{

			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}

	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
		catch (NullPointerException e)
		{
			line=null;

		}

	}

	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);

		//System.out.println("I read this number: " + val);
		return val;
	}

	long NextLong()
	{
		String n = inputParser.nextToken();
		long val = Long.parseLong(n);

		//System.out.println("I read this number: " + val);
		return val;
	}

	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}

	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}

	}

	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		new A(filePath);
	}

	public void readFInput()
	{
		for(;;)
		{
			try
			{
				readNextLine();
				FInput+=line+" ";
			}
			catch(Exception e)
			{
				break;
			}
		}
		inputParser = new StringTokenizer(FInput, " ");
	}

	public A(String inputFile)
	{
		openInput(inputFile);

		readNextLine();
		int n=NextInt();
    	int a=NextInt();
    	int b=NextInt();
		int ret=0;
		readNextLine();
		int [] p = new int[n];
		for(int i=0; i<n; i++)
		{
			p[i]=NextInt();
		}
		Arrays.sort(p);
		int id=0,cnt=0;
		while(id<n&&cnt<b)
		{
			cnt++;
			id++;
		}
		if(id<n)
		{
			ret=p[id]-p[id-1];
		}

		System.out.print(ret);
        closeInput();
	}

}


import java.io.*;
import java.util.*;

public class ayyyyyy
{
	public static void main(String[] args) { new ayyyyyy(); }
	Scanner in = new Scanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	int t, n;
	int[] a;

	ayyyyyy()
	{
		t = in.nextInt();
		while (t --> 0)
		{
			a = new int[n = in.nextInt()];
			for (int i = 0; i < n; i++)
				a[i] = in.nextInt();
			shuffle(a);
			Arrays.sort(a);
			out.println(Math.min(n-2, a[n-2]-1));
		}

		out.close();
	}

	void shuffle(int[] x)
	{
		for (int i = 0; i < n; i++)
		{
			int swp = (int)(n*Math.random());
			int tmp = x[swp];
			x[swp] = x[i];
			x[i] = tmp;
		}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class A {
    static MyScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws Throwable {
        sc = new MyScanner();
        pw = new PrintWriter(System.out);

        n = sc.nextInt();
        T = sc.nextLong();
        p = new int[n];
        l = new int[n];
        x = new int[n];
        t = new int[n];
        adj = new ArrayList[n];

        for (int i = 0; i < n; i++)
            x[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            t[i] = sc.nextInt();
        adj[0] = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            adj[i] = new ArrayList<>();
            p[i] = sc.nextInt() - 1;
            l[i] = sc.nextInt();
            adj[p[i]].add(i);
        }

        ftCnt = new long[N];
        ftSum = new long[N];
        ans = new long[n];

        dfs(0);
        pw.println(ans[0]);

        pw.flush();
        pw.close();
    }

    static int n;
    static long T;
    static int[] p, l, x, t;
    static ArrayList<Integer>[] adj;

    static long[] ans;

    static void dfs(int u) {
        update(t[u], x[u], 1L * x[u] * t[u]);
        ans[u] = getMaxCnt();
        long[] vals = {-1, -1, -1};
        for (int v : adj[u]) {
            T -= 2 * l[v];
            dfs(v);
            vals[0] = ans[v];
            Arrays.sort(vals);
            T += 2 * l[v];
        }
        if (u != 0) {
            if (vals[1] != -1)
                ans[u] = Math.max(ans[u], vals[1]);
        } else {
            if (vals[2] != -1)
                ans[u] = Math.max(ans[u], vals[2]);
        }
        update(t[u], -x[u], -1L * x[u] * t[u]);
    }

    static int N = (int) 1e6 + 2;
    static long[] ftCnt, ftSum;

    static void update(int idx, long cnt, long val) {
        while (idx < N) {
            ftCnt[idx] += cnt;
            ftSum[idx] += val;
            idx += (idx & -idx);
        }
    }

    static long getSum(int idx) {
        long ret = 0;
        while (idx > 0) {
            ret += ftSum[idx];
            idx -= (idx & -idx);
        }
        return ret;
    }

    static long getCnt(int idx) {
        long ret = 0;
        while (idx > 0) {
            ret += ftCnt[idx];
            idx -= (idx & -idx);
        }
        return ret;
    }

    static long getMaxCnt() {
        int start = 1, end = N - 1, ans = N - 1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (getSum(mid) >= T) {
                ans = mid;
                end = mid - 1;
            } else
                start = mid + 1;
        }
        long remT = T - (ans > 1 ? getSum(ans - 1) : 0);
        long cnt = (ans > 1 ? getCnt(ans - 1) : 0);
        long cntOfVal = getCnt(ans) - cnt;
        cnt += Math.min(cntOfVal, remT / ans);
        return cnt;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.math.*;
public class Split {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int k= sc.nextInt();
		int a[] = new int[n];
		int d[] = new int[n-1];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			if(i>0)
				d[i-1] = a[i-1] - a[i];
		}
		Arrays.sort(d);
		int t = 0;
		for(int i=0;i<k-1;i++)
			t += d[i];
		System.out.println(a[n-1]-a[0]+t);
	}

}


import java.io.*;
import java.util.*;

import javax.lang.model.util.ElementScanner6;
public class codef
{
    public static void main(String ar[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer nk=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(nk.nextToken());
        int k=Integer.parseInt(nk.nextToken());
        String st[]=br.readLine().split(" ");

        int ans[]=new int[n];
        int a[]=new int[n];
        for(int i=0;i<n;i++)
            ans[i]=Integer.parseInt(st[i]);

        for(int i=1;i<n;i++)
            a[i]=ans[i]-ans[i-1];
        a[0]=-1;

        Arrays.sort(a);
        int count=0,sum=0;
        for(int i=0;i<n;i++)
            if(a[i]<0)
                count++;
            else
                sum=sum+a[i];

        k=k-count;
        int i=n-1;
        while(k>0 && i>=0)
        {
            if(a[i]>-1)
            {
                sum=sum-a[i];
                k--;
            }
            i--;
        }
        System.out.println(sum);
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		for(int i = n-1; i > 0; i--)
			arr[i] -= arr[i-1];
		arr[0] = 0;
		Arrays.sort(arr);
		long sum = 0;
		for(int i = n-k; i >= 0; i--)
			sum += arr[i];
		System.out.println(sum);
	}
}


import java.io.*;
import java.util.*;

import static java.lang.System.out;

public class Main {

    private FastScanner scanner = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    private List<Integer>[] gr = new ArrayList[1000_000+5];
    private int dp[][] = new int[21][1000_000+5];
    private boolean used[] = new boolean[1000_000+5];

    void init(int v, int p) {
        Stack<Integer> st = new Stack<>();
        st.push(v);
        st.push(p);
        while (!st.isEmpty()) {
            p = st.pop();
            v = st.pop();
            used[v] = true;

            dp[0][v] =  p;
            for (int i = 1; i <= 20; i++) {
                if (dp[i - 1][v] != -1) {
                    dp[i][v] = dp[i - 1][dp[i - 1][v]];
                }
            }

            for (int next : gr[v]) {
                if (!used[next]) {
                    st.push(next);
                    st.push(v);
                }
            }

        }
    }

    private void solve() {
        int n = scanner.nextInt(), k = scanner.nextInt();
        boolean[] ans = new boolean[1000_000 + 5];

        for (int i = 0; i < n; i++) {
            gr[i] = new ArrayList<>();
        }

        for (int i = 0; i < n - 1; i ++) {
            int u = scanner.nextInt() - 1, v = scanner.nextInt() - 1;
            gr[u].add(v);
            gr[v].add(u);
        }

        k = n - k - 1;
        ans[n - 1] = true;

        init(n - 1 , n - 1);

        int t, d, next;
        for (int i = n - 2; i >= 0; i--) {
            t = i;
            d = 1;
            if (ans[i]) {
                continue;
            }
            for (int j = 20; j >= 0; j--){
                next = dp[j][t];
                if (next != -1 && !ans[next]) {
                    t = next;
                    d +=  1 << j;
                }
            }

            if (d <= k) {
                k -=d;
                t = i;

                while (!ans[t]) {
                    ans[t] = true;
                    t = dp[0][t];
                }
            }
            if (k == 0) {
                break;
            }
        }
        StringBuilder sb = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            if (!ans[i]) {
                sb.append(i + 1).append(" ");
            }
        }
        System.out.println(sb.toString());
    }

    class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}


import java.util.*;
import java.io.*;
public class a {
  static long mod = 1000000007;
  static boolean[][] blacks;
public static void main(String[] args) throws IOException
{
  input.init(System.in);
  PrintWriter out = new PrintWriter(new PrintStream(System.out));
  //Scanner input = new Scanner(new File("input.txt"));
  //PrintWriter out = new PrintWriter(new File("output.txt"));

  int n = input.nextInt(), t = input.nextInt();
  int res = 2;
  Cottage[] data = new Cottage[n];
  int[] xs = new int[n], as = new int[n];
  for(int i = 0; i<n; i++)
  {
    data[i] = new Cottage(input.nextInt(), input.nextInt());
  }
  Arrays.sort(data);
  for(int i = 0; i<n; i++)
  {
    xs[i] = data[i].x;
    as[i] = data[i].a;
  }
  for(int i = 0; i<n-1; i++)
  {
    if(2*(xs[i+1]-xs[i]) == 2*t+as[i]+as[i+1]) res++;
    else if(2*(xs[i+1]-xs[i]) > 2*t+as[i]+as[i+1]) res+=2;
  }
  out.println(res);

  out.close();
}
static class Cottage implements Comparable<Cottage>
{

  /* (non-Javadoc)
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  int x, a;
  public Cottage(int xx, int aa)
  {
    x = xx; a = aa;
  }
  @Override
  public int compareTo(Cottage o) {
    // TODO(mkirsche): Auto-generated method stub
    return this.x - o.x;
  }

}
static long pow(long a, long p)
{
  if(p==0) return 1;
  if((p&1) == 0)
  {
    long sqrt = pow(a, p/2);
    return (sqrt*sqrt)%mod;
  }
  else
    return (a*pow(a,p-1))%mod;
}
static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;

  /** call this method to initialize reader for InputStream */
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }

  /** get next word */
  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          //TODO add check for eof if necessary
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }
  static long nextLong() throws IOException {
    return Long.parseLong( next() );
}

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static String nextLine() throws IOException {
    return reader.readLine();
  }
}
}


import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.File;

public class Task{

	static final boolean readFromFile = false;
	static final String fileInputName = "input.txt",
						fileOutputName = "output.txt";

	public static void main(String args[]){
		FileInputStream fileInputStream;
		FileOutputStream fileOutputStream;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (readFromFile){
			try{
				fileInputStream = new FileInputStream(new File(fileInputName));
				fileOutputStream = new FileOutputStream(new File(fileOutputName));
			}catch (FileNotFoundException e){
				throw new RuntimeException(e);
			}
		}
		PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
		InputReader in  = new InputReader((readFromFile)?fileInputStream:inputStream);

		Solver s = new Solver(in, out);
		s.solve();

		out.close();
	}
}

class Solver{
	private PrintWriter out;
	private InputReader in;

	public void solve(){
		int n = in.nextInt();
		double t = in.nextDouble(),
			a[] = new double[n],
			x[] = new double[n];
		for (int i=0;i<n;i++){
			x[i] = in.nextDouble();
			a[i] = in.nextDouble();
		}
		int ans = 2;
		for (int i=0;i<n-1;i++)
			for (int j=i+1;j<n;j++)
				if (x[j]<x[i]){
					double buf = x[i];x[i]=x[j];x[j]=buf;
					buf = a[i]; a[i]=a[j];a[j]=buf;
				}

		for (int i=0;i<n-1;i++){
			if (x[i]+a[i]/2+t<x[i+1]-a[i+1]/2)
				ans += 2;
			if (x[i]+a[i]/2+t==x[i+1]-a[i+1]/2)
				ans++;
		}
		out.println(ans);
	}

	Solver(InputReader in, PrintWriter out){
		this.in = in;
		this.out = out;
	}
}

class InputReader{
	StringTokenizer tok;
	BufferedReader buf;

	InputReader(InputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	InputReader(FileInputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	public String next(){
		while (tok==null || !tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(buf.readLine());
			}catch (IOException e){
				throw new RuntimeException(e);
			}
		}
		return tok.nextToken();
	}

	public int nextInt(){
		return Integer.parseInt(next());
	}
	public long nextLong(){
		return Long.parseLong(next());
	}
	public double nextDouble(){
		return Double.parseDouble(next());
	}
	public float nextFloat(){
		return Float.parseFloat(next());
	}
	public String nextLine(){
		try{
			return buf.readLine();
		}catch (IOException e){
			return null;
		}
	}
}


    import java.awt.Point;
import java.io.*;
    import java.text.*;
    import java.util.*;
import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            Pair<Double,Double>[] p;
            int n, t;

            int find() {
                int count = 2;

                for(int i = 0; i < n-1; ++i) {
                    double dif = p[i+1].a-p[i].b;
                    int comp = Double.compare(dif,t);

                    if(comp==0)
                        count+=1;
                    else
                        if(comp>0)
                            count+=2;
                }

                return count;
            }

            @Override
            public void run() {
                n = nextInt();
                t = nextInt();

                p = new Pair[n];
                for(int i = 0; i < n; ++i) {
                    int x = nextInt()+1000;
                    int a = nextInt();

                    double h = a/(double)2;
                    p[i] = new Pair<Double,Double>(x-h,x+h);
                }

                Arrays.sort(p, new PComparator());
                print(find());
                close();
            }

            class PComparator implements Comparator<Pair<Double,Double>> {
                @Override
                public int compare(Pair<Double, Double> o1,
                        Pair<Double, Double> o2) {

                    return Double.compare(o1.a, o2.a);
                }
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void println(Object o) {
                out.write(o.toString() + '\n');
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }

            @Override
            public String toString() {
                return a+" "+b;
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


import java.util.*;

public class A {

	public static double EPS = .001;

	public class House implements Comparable<House> {
		int x;
		int a;

		public House(int mx, int ma) {
			x = mx;
			a = ma;
		}

		public int compareTo(House o) {
			return x - o.x;
		}

		public double right() {
			return (double)x + ((double)a)/2.0;
		}

		public double left() {
			return (double)x - ((double)a)/2.0;
		}
	}

	public static void main(String[] args) {
		new A().solve();
	}

	public void solve() {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int t = in.nextInt();

		ArrayList<House> houses = new ArrayList<House>();

		for(int i=0;i<n;i++) {
			int x = in.nextInt();
			int a = in.nextInt();
			houses.add(new House(x,a));
		}

		Collections.sort(houses);

		int total = 2;

		for(int i=0;i<houses.size()-1;i++) {
			House me = houses.get(i);
			House next = houses.get(i+1);
			double meright = me.right();
			double nextleft = next.left();
			double diff = nextleft - meright;
			if(diff-EPS > ((double)t)) {
				total += 2;
			}
			else if(diff+EPS > ((double)t)) {
				total += 1;
			}
		}

		System.out.println(total);
	}

}


import java.util.*;

public class Village {
	private class House implements Comparable<House>{
		Double Coordinate;
		Double Sidelength;
		public House(double coordinate, double sidelength) {
			Coordinate = coordinate;
			Sidelength = sidelength;
		}
		public int compareTo(House o) {
			return Coordinate.compareTo(o.Coordinate);
		}
	}

	public static void main(String args[]) {
		Village v = new Village();
		v.solve();
	}
	public void solve() {
	Scanner in = new Scanner(System.in);
	int numhouse = in.nextInt();
	double requireside = in.nextDouble();
	//System.out.println(numhouse);
	//System.out.println(requireside);
	ArrayList<House> coordinate = new ArrayList<House>();
	ArrayList<Double> sidelength = new ArrayList<Double>();
	while (in.hasNext()) {
		double coo = in.nextDouble();
		double side = in.nextDouble();
		//System.out.println(coo);
		//System.out.println(side);
		coordinate.add(new House(coo,side));
		sidelength.add(side);
		}
	Collections.sort(coordinate);
	ArrayList<Double> edges = new ArrayList<Double>();
	int count = 2;
	for (int i = 0; i < coordinate.size();i++) {
		edges.add(coordinate.get(i).Coordinate - (double)coordinate.get(i).Sidelength/(double)2);
		edges.add(coordinate.get(i).Coordinate + (double)coordinate.get(i).Sidelength/(double)2);
	}
	ArrayList<Double> difference = new ArrayList<Double>();
	for (int i = 1; i < edges.size() - 1; i++) {
		difference.add(Math.abs(edges.get(i) - edges.get(i+1)));
	}
	for (int i = 0; i < difference.size(); i+=2) {
		if (difference.get(i) == requireside) count++;
		else if (difference.get(i) > requireside) count+=2;
	}
	System.out.println(count);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class A15 {

	static StreamTokenizer in;
	static PrintWriter out;

	static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}

	static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws IOException {
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
		out = new PrintWriter(System.out);

		int n = nextInt(), t = nextInt();

		int[] x = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = nextInt();
			a[i] = nextInt();
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			boolean left = true, right = true;
			for (int j = 0; j < n; j++)
				if (x[j] < x[i] && a[i] + 2*t + a[j] >= 2*Math.abs(x[i] - x[j])) left = false;
				else if (x[j] > x[i] && a[i] + 2*t + a[j] > 2*Math.abs(x[i] - x[j])) right = false;
			if (left) ans++;
			if (right) ans++;
		}

		out.println(ans);

		out.flush();
	}
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author madi
 */
public class CottageTown {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] in = sc.nextLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int t = Integer.parseInt(in[1]);

        int[] coor = new int[n];
        int[] side = new int[n];

        for (int i = 0; i < n; i++) {
            in = sc.nextLine().split(" ");
            coor[i] = Integer.parseInt(in[0]);
            side[i] = Integer.parseInt(in[1]);
        }

        quickSort(coor, 0, n - 1, side);

        int count = 2;
        double dist;
        for (int i = 0; i < n - 1; i++) {
            dist = (coor[i + 1] - coor[i]) - (double)(side[i + 1] + side[i]) / 2.0;
            if (dist > t) {
                count += 2;
            } else if (dist == t) {
                count += 1;
            }
        }

        System.out.println(count);

    }

    private static int partition(int[] arr, int left, int right, int[] temp) {
        int i = left, j = right;
        int tmp;
        int pivot = arr[(left + right) / 2];

        while (i <= j) {
            while (arr[i] < pivot) {
                i++;
            }
            while (arr[j] > pivot) {
                j--;
            }
            if (i <= j) {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;

                tmp = temp[i];
                temp[i] = temp[j];
                temp[j] = tmp;

                i++;
                j--;
            }
        }

        return i;
    }

    private static void quickSort(int[] arr, int left, int right, int[] temp) {
        int index = partition(arr, left, right, temp);
        if (left < index - 1) {
            quickSort(arr, left, index - 1, temp);
        }
        if (index < right) {
            quickSort(arr, index, right, temp);
        }
    }
}


import java.util.Scanner;

public class Flatwile {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int[] c = new int[n];
        int[] a = new int[n];
        for (int i=0; i<n; i++){
            c[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }
        sort(c, a);
        int res = 1;
        double prev = Integer.MIN_VALUE;
        for(int i=0; i<c.length; i++){
            if (c[i]-a[i]/2d - prev >=t){
                res++;
            }
            if (i!=c.length-1 && c[i+1]-a[i+1]/2d-(c[i]+a[i]/2d)>t ){
                res++;
            }
            prev = c[i] +a[i]/2d;
        }
        System.out.println(res);
    }

    private static void sort(int[] a, int[] b){
        for(int i=0; i<a.length; i++){
            for(int j=i+1; j<a.length; j++){
                if (a[i]>a[j]){
                    swap(a, i, j);
                    swap(b, i, j);
                }
            }
        }
    }

    private static void swap(int[] a, int i, int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

}


import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        new A().solve();
    }

    public void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        float[] left = new float[n];
        float[] right = new float[n];
        for (int i=0; i<n; ++i) {
            int c = sc.nextInt();
            int w = sc.nextInt();
            left[i] = (float) (c - (float) w * 1.0 / 2);
            right[i] = (float) (c + (float) w * 1.0 / 2);
        }
        for (int i=0; i<n; ++i)
            for (int j=i+1; j<n; ++j)
                if (left[j] < left[i]) {
                    float tmp = left[i];
                    left[i] = left[j];
                    left[j] = tmp;
                    tmp = right[i];
                    right[i] = right[j];
                    right[j] = tmp;
                }
        int res = 2;
        for (int i=1; i<n; ++i) {
            float dis = left[i] - right[i-1];
            if (Math.abs(dis - t) < 0.000001)
                res ++;
            if ((dis - t) > 0.000001)
                res += 2;
        }
        System.out.println(res);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Houses implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int t = nextInt();
        int[] x = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            x[i] = nextInt() * 2;
            a[i] = nextInt();
        }
        Set<Integer> res = new HashSet<Integer>();
        for (int i = 0; i < n; ++i) {
            if (valid(n, t, x, a, x[i] + a[i] + t))
                res.add(x[i] + a[i] + t);
            if (valid(n, t, x, a, x[i] - a[i] - t))
                res.add(x[i] - a[i] - t);
        }
        writer.println(res.size());
    }

    private boolean valid(int n, int t, int[] x, int[] a, int pos) {
        for (int i = 0; i < n; ++i) {
            if (Math.abs(pos - x[i]) < a[i] + t)
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        new Houses().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.util.*;
public class C15A {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int t=sc.nextInt();
        double nm[][]=new double[n][2];
        int a=0;
        int b=0;
        for(int i=0;i<n;i++){
            a=sc.nextInt();
            b=sc.nextInt();
            nm[i][0]=a-(double)b/2;
            nm[i][1]=a+(double)b/2;
        }

        Arrays.sort(nm, new ArrayColumnComparator(1));

        int sum=0;
        for(int i=0;i<n-1;i++){
            if(nm[i+1][0]-nm[i][1]==t)
                sum++;
            else if(nm[i+1][0]-nm[i][1]>t){
                sum+=2;
            }

        }

        System.out.println(sum+2);
    }

}
class ArrayColumnComparator implements Comparator {
    private int cm = 0;
    ArrayColumnComparator(int cm) {
        this.cm = cm;
    }
    public int compare(Object o1, Object o2) {
        double[] row1 = (double[])o1;
        double[] row2 = (double[])o2;
        int i;
        if (row1[cm]>row2[cm])
            i=1;
        else if(row1[cm]<row2[cm])
            i=-1;
        else i=0;
        return i;
    }
}


import java.util.*;
import static java.lang.Math.*;

public class Main{
  public static void main(String[] args){
    new Main().run();
  }

  void run(){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt() * 2;
    H[] tbl = new H[n];
    for(int i = 0; i < n; i++)tbl[i] = new H(sc.nextInt()*2, sc.nextInt()*2);
    Arrays.sort(tbl);
    TreeSet<Integer> cand = new TreeSet<Integer>();
    //cand.add(tbl[0].x - tbl[0].len / 2);
    for(int i = 0; i < n; i++){
      int left = tbl[i].x - tbl[i].len / 2 - t / 2;
      if(!cand.contains(left)){
        if(i > 0 && tbl[i-1].x + tbl[i-1].len/2 > left - t/2){

        }else{
          cand.add(left);
        }
      }
      int right = tbl[i].x + tbl[i].len / 2 + t/2;
      if(!cand.contains(right)){
        if(i < n-1 && tbl[i+1].x - tbl[i+1].len/2 < right + t/2){

        }else{
          cand.add(right);
        }
      }
    }
    System.out.println(cand.size());
  }

  class H implements Comparable<H>{
    int x, len;
    H(int a, int b){
      x = a;
      len = b;
    }
    public int compareTo(H h){
      return this.x - h.x;
    }
  }
}


import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int k=0,i=0,j=0,n=0,p=0,t=0;
String s;
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
n=Integer.parseInt(c.nextToken());
k=Integer.parseInt(c.nextToken());
int d[]=new int[n];
int e[]=new int[n];
for(i=0;i<n;i++)
{
s=b.readLine();
StringTokenizer z=new StringTokenizer(s);
d[i]=Integer.parseInt(z.nextToken());
e[i]=Integer.parseInt(z.nextToken());
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(d[j]<d[i])
{
t=d[j];
d[j]=d[i];
d[i]=t;
t=e[j];
e[j]=e[i];
e[i]=t;
}
}
}
for(i=0;i<n-1;i++)
{
if(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))>k)
p+=2;
if(((d[i+1]-e[i+1]/2.0)-(d[i]+e[i]/2.0))==k)
p++;
}
System.out.print(p+2);
}
}


import java.io.*;
import java.text.*;
import java.util.*;

public class CottageVillage {

	static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;

	static String LINE() throws Exception { return stdin.readLine(); }
	static String TOKEN() throws Exception {
		while (st == null || !st.hasMoreTokens())st = new StringTokenizer(LINE());
		return st.nextToken();
	}
	static int INT() throws Exception {return Integer.parseInt(TOKEN());}
	static long LONG() throws Exception {return Long.parseLong(TOKEN());}
	static double DOUBLE() throws Exception {return Double.parseDouble(TOKEN());}

	static DecimalFormat DF = new DecimalFormat("0.000",new DecimalFormatSymbols(Locale.ENGLISH));

	public static final double EPSILON = 1E-9;

	public static void main(String[] args) throws Exception {
		int N = INT(), T = INT();
		House[] list = new House[N];
		for(int i = 0;i<N;i++) {
			list[i] = new House(INT(),INT());
		}
		Arrays.sort(list);
		int cnt = 2;
		for(int i = 1;i<N;i++) {
			int room = list[i].center-list[i-1].center;
			if(2*T<2*room-list[i].side-list[i-1].side)cnt += 2;
			else if(2*T==2*room-list[i].side-list[i-1].side)cnt++;
		}
		System.out.println(cnt);

	}

	private static class House implements Comparable<House> {
		int center, side;
		House(int c, int s) {
			this.center = c;
			this.side = s;
		}
		public int compareTo(House h) {
			return this.center-h.center;
		}
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class A {

    static class Entity implements Comparable {

        public Entity(int x, int a) {
            this.x = x;
            this.a = a;
        }
        public int x, a;

        public int compareTo(Object t) {
            Entity o = (Entity) t;
            return x == o.x ? 0 : x < o.x ? -1 : 1;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), t = 2 * scanner.nextInt();
        if (1 == n) {
            System.out.println(2);
        } else {
            int rez = 2;
            ArrayList<Entity> list = new ArrayList<Entity>();
            for (int i = 0; i < n; i++) {
                list.add(new Entity(scanner.nextInt(), scanner.nextInt()));
            }
            Collections.sort(list);
            for (int i = 1; i < n; i++) {
                int num = 2 * (list.get(i).x - list.get(i - 1).x)
                        - list.get(i).a - list.get(i - 1).a;
                if (t < num) {
                    rez += 2;
                } else if (t == num) {
                    rez++;
                }
            }
            System.out.println(rez);
        }
    }
}