codeparrot/codecomplex huggingface dataset:
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class A {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    
    class Team implements Comparable<Team>{
        int ac;
        int penalty;
        
        public Team(int ac, int penalty) {
            this.ac = ac;
            this.penalty = penalty;
        }

        @Override
        public int compareTo(Team o) {
            if (ac != o.ac)
                return ac > o.ac ? -1 : 1;
            return (penalty == o.penalty) ? 0 : (penalty < o.penalty ? -1 : 1);
        }
        
    }

    void solve() throws IOException {
        int n = nextInt();
        int k = nextInt() - 1;
        
        Team[] a = new Team[n];
        for (int i = 0; i < n; i++)
            a[i] = new Team(nextInt(), nextInt());
        
        Arrays.sort(a);
        for (int i = 0; i < n;) {
            int j = i;
            while (j < n && a[j].compareTo(a[i]) == 0)
                j++;
            if (i <= k && k < j) {
                out.println(j - i);
                return;
            }
            i = j;
        }
    }

    void inp() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

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

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

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

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

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.awt.Point;
import static java.lang.Math.*;

public class P166A {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        Point[] P = new Point[n];
        for(int i=0; i<n; i++)
            P[i] = new Point(in.nextInt(), in.nextInt());
        Arrays.sort(P, new Comparator<Point>() {
            public int compare(Point A, Point B) {
                if(A.x != B.x) return B.x-A.x;
                return A.y - B.y;
            }
        });
        int cnt = 0;
        Point ans = P[k-1];
        for(int i=0; i<n; i++) {
            if(P[i].x == ans.x && P[i].y==ans.y)
                cnt++;
        }
        System.out.println(cnt);
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

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

	void run() {

		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	PrintWriter out;
	Scanner in;

	class Pair {
		int x;
		int y;

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

		@Override
		public String toString() {
			return x + " " + y;
		}
	}

	int[] readArr(int size) {
		int[] a = new int[size];
		for (int i = 0; i < size; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		Pair[] a = new Pair[n];
		for (int i = 0; i < n; i++) {
			a[i] = new Pair(in.nextInt(), in.nextInt());
		}
		Arrays.sort(a, new Comparator<Pair>() {

			@Override
			public int compare(Pair p1, Pair p2) {
				if (p2.x != p1.x) {
					return p2.x - p1.x;
				}
				return p1.y - p2.y;
			}
		});
		int cnt = 1;
		int ans = 0;
		int[] res = new int[n];
		res[0] = 1;
		for (int i = 1; i < n; i++) {
			if (!(a[i].x == a[i - 1].x && a[i].y == a[i - 1].y)) {
				cnt++;
			}
			res[i] = cnt;
			//out.println(a[i] + " * " + cnt);
		}
		int el = res[k - 1];
		for (int i = 0; i < n; i++) {
			if (res[i] == el) {
				ans++;
			}
		}
		out.println(ans);

	}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;


public class A {

    static StreamTokenizer st;
    static PrintWriter pw;
    static class Sort implements Comparable<Sort> {
        int x,y;
        public int compareTo(Sort arg0) {
            if (this.x==arg0.x)
                return this.y-arg0.y;
            return -(this.x-arg0.x);
        }
    }
    public static void main(String[] args) throws IOException{
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int k = nextInt();
        Sort[]a = new Sort[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = new Sort();
            a[i].x = nextInt();
            a[i].y = nextInt();
        }
        Arrays.sort(a,1, n+1);
//      for (int i = 1; i <= n; i++) {
//          System.out.println(a[i].x+" "+a[i].y);
//      }
//      int plase = 1;
//      if (k==1) {
//          int ans = 0;
//          for (int j = 1; j <= n; j++) {
//              if (a[j].x==a[1].x && a[j].y ==a[1].y) {
//                  ans++;
//              }
//          }
//          System.out.println(ans);
//          return;
//      }
//      for (int i = 2; i <= n; i++) {
//          if (a[i].x==a[i-1].x && a[i].y==a[i-1].y) {
//              
//          }
//          else {
//              plase++;
//              if (plase==k) {
//                  int ans = 0;
//                  for (int j = 1; j <= n; j++) {
//                      if (a[j].x==a[i].x && a[j].y ==a[i].y) {
//                          ans++;
//                      }
//                  }
//                  System.out.println(ans);
//                  return;
//              }
//          }
//      }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i].x==a[k].x && a[i].y==a[k].y)
                ans++;
        }
        System.out.println(ans);
        pw.close();
    }
    private static int nextInt() throws IOException{
        st.nextToken();
        return (int) st.nval;
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn

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

public class A {

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n  = scan.nextInt();
		int k = scan.nextInt()-1;
		team[] t = new team[n];
		for(int i = 0 ;i  < n ; i++)
			t[i] = new team(scan.nextInt(), scan.nextInt());
		Arrays.sort(t);
		int a =0;
		int b = 0;
		while(k+a < t.length-1 && t[k+a+1].compareTo(t[k]) == 0)
			a++;
		while(k-b > 0 && t[k-b-1].compareTo(t[k]) == 0)
			b++;
		System.out.println(a+b+1);
	}

}
class team implements Comparable<team>
{
	int p;
	int t;
	public team(int pp , int tt)
	{
		p = pp;
		t= tt;
	}
	@Override
	public String toString()
	{
		return p+" "+t;
	}
	@Override
	public int compareTo(team e)
	{
		int a = e.p-p;
		if(a == 0)
		{
			return  t-e.t;
		}else
			return a;
	}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt() - 1 ;
        int a[][] = new int[n][2];
        for (int i = 0;i <n; i++) {
            a[i][0]=input.nextInt();
            a[i][1]=input.nextInt();
        }
        for (int i = 0; i<n; i++) {
            for (int j=i+1; j<n; j++) {
                if (a[i][0]<a[j][0]) {
                    int x=a[i][0];
                    int y=a[i][1];
                    a[i][0]=a[j][0];
                    a[i][1]=a[j][1];
                    a[j][0]=x;
                    a[j][1]=y;
                    
                }
            }
        }
        for (int i = 0; i<n; i++) {
            for (int j=i+1; j<n; j++) {
                if ((a[i][1]>a[j][1])&&(a[i][0]==a[j][0])) {
                    int x=a[i][0];
                    int y=a[i][1];
                    a[i][0]=a[j][0];
                    a[i][1]=a[j][1];
                    a[j][0]=x;
                    a[j][1]=y;
                    
                }
            }
        }
        int x = a[k][0];
        int y = a[k][1];
        int s = 0;
        for (int i = 0; i<n; i++) {
            if ((a[i][0]==x)&&(a[i][1]==y)) {
                s++;
            }
        }
        System.out.println(s);
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
//package codeforces;

import java.util.*;

public class Main {
    class team implements Comparable<team>{
        int pro,time;

        public int compareTo(team oth) {
            if(pro>oth.pro)
                return -1;
            if(pro==oth.pro&&time<oth.time)
                return -1;
            // TODO Auto-generated method stub
            return 1;
        }
        
    }
    Scanner scan=new Scanner(System.in);
    void run(){
        int n=scan.nextInt();
        int k=scan.nextInt()-1;
        team tm[]=new team[n];
        for(int i=0;i<n;i++){
            tm[i]=new team();
            tm[i].pro=scan.nextInt();
            tm[i].time=scan.nextInt();
        }
        Arrays.sort(tm);
        int sum=0;
        
        for(int i=k;i>=0;i--)
            if(tm[i].pro==tm[k].pro&&tm[i].time==tm[k].time)
                sum++;
        for(int i=k;i<n;i++)
            if(tm[i].pro==tm[k].pro&&tm[i].time==tm[k].time)
                sum++;
        System.out.println(sum-1);
    }
    public static void main(String args[]) {
         
        new Main().run();
    }

}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;


public class Main {

    private void solve() {
        int n = in.nextInt();
        int k = in.nextInt();
        final int[] p = new int[n];
        final int[] t = new int[n];
        for(int i =0 ; i < n; ++i) {
            p[i] = in.nextInt();
            t[i] = in.nextInt();
        }
        Integer[] ord = new Integer[n];
        for(int i = 0; i < n; ++i)
            ord[i] = i;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n - 1; ++j) {
                if (Less(ord[j], ord[j + 1], p, t)) {
                    Integer tx = ord[j];
                    ord[j] = ord[j + 1];
                    ord[j + 1] = tx;
                }
            }
        }
        
        
        
        for(int i = 0, j = 0; i < n; i = j) {
            for(j = i; j < n && p[ord[i]] == p[ord[j]] && t[ord[i]] == t[ord[j]]; ++j) ;
            int first = i+1;
            int second = j;
            if (first <= k && k <= second) {
                out.print(j - i);
                return ;
            }
        }
        out.print(0);
    }
    private boolean Less(Integer i, Integer j, int[] p, int[] t) {
        return p[i] < p[j] || p[i] == p[j] && t[i] > t[j];
    }
    private void run() {
        try {
            in = new FastScanner();
            out = new PrintWriter(new OutputStreamWriter(System.out));
            solve();
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        new Main().run();
    }
    FastScanner in;
    PrintWriter out;
    class FastScanner {
        public BufferedReader reader;
        private StringTokenizer tokenizer;
        public FastScanner(String file) {
            try {
                reader = new BufferedReader(new FileReader(new File(file)));
                tokenizer = null;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        
        public FastScanner() {
            try {
                reader = new BufferedReader(new InputStreamReader(System.in));
                tokenizer = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        public String nextToken() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(nextToken());
        }
        long nextLong() {
            return Long.parseLong(nextToken());
        }
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
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.Comparator;
import java.util.Locale;
import java.util.StringTokenizer;

public class A {
	
	private class Pair {
		public final int prob;
		public final int time;
		
		public Pair(int prob, int time) {
			this.prob = prob;
			this.time = time;
		}
	}
	
	private void solve() throws IOException {
		int n = nextInt();
		int k = nextInt();
		
		Pair[] p = new Pair[n];
		for (int i = 0; i < n; i++) {
			p[i] = new Pair(nextInt(), nextInt());
		}
		
		Arrays.sort(p, new Comparator<Pair>() {
			@Override
			public int compare(Pair o1, Pair o2) {
				if (o1.prob == o2.prob) {
					return o1.time - o2.time;
				}
				return o2.prob - o1.prob;
			}
		});
		
		int time = p[k - 1].time;
		int prob = p[k - 1].prob;
		int res = 0;
		for (int i = 0; i < n; i++) {
			if (p[i].time == time && p[i].prob == prob) {
				res++;
			}
		}
		println(res);
	}

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

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

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

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

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new A().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;

public class Round113_A {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt() - 1;
        Obe[] a = new Obe[n];
        for (int i = 0; i < n; i++)
            a[i] = new Obe(in.nextInt(), in.nextInt());

        Arrays.sort(a);
        int c = 0;

        int p = 0, d = 0;
        if (k > -1 && k < n) {
            c = 1;
            p = a[k].p;
            d = a[k].d;
        } else {
            System.out.println(c);
            return;
        }
        for (int i = k + 1; i < n; i++) {
            if (a[i].p == p && a[i].d == d)
                c++;
        }
        for (int i = k - 1; i > -1; i--) {
            if (a[i].p == p && a[i].d == d)
                c++;
        }
        System.out.println(c);
    }

}

class Obe implements Comparable<Obe> {

    int p, d;

    public Obe(int pe, int de) {
        p = pe;
        d = de;
    }

    @Override
    public int compareTo(Obe o) {
        int x = new Integer(o.p).compareTo(this.p);
        if (x != 0)
            return x;
        return new Integer(this.d).compareTo(o.d);
    }

}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
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 {
     class Pair{
		public int a;
		public int b;
		public Pair(int a, int b) {
			// TODO Auto-generated constructor stub
			this.a = a;
			this.b = b;
		}
	}

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();  --k;
        ArrayList<Pair> list = new ArrayList<Pair>();
		for (int i = 1; i <= n; ++i){
            int num = in.nextInt();
            int pen = in.nextInt();
			Pair t = new Pair(num, pen);
		    list.add(t);
        }
        Collections.sort(list, new Comparator<Pair>(){
				public int compare(Pair o1, Pair o2){
					if (o1.a != o2.a){
						return (o2.a - o1.a);
					}
					return (o1.b - o2.b);
				}
		});

        int res = 1;
        Pair compare = list.get(k);
        int i = k - 1;
        while (i >= 0){
            Pair t = list.get(i);
            if (t.a == compare.a && t.b == compare.b){
                --i;
                ++res;
                continue;
            }else{
                break;
            }
        }
       i = k + 1;
        while (i < list.size()){
            Pair t = list.get(i);
            if (t.a == compare.a && t.b == compare.b){
                ++res; ++i;
                continue;
            }else{
                break;
            }
        }
        out.println(res);
       return;
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class P113A {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = System.out;
        //CODING TAIM

        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Team> l = new ArrayList<Team>();
        for (int i = 0; i < n; i++) {
            l.add(new Team(sc.nextInt(), sc.nextInt()));
        }
        Collections.sort(l, new Comparator<Team>() {
                public int compare(Team a, Team b) {
                    if (a.s == b.s)
                        return a.t - b.t;
                    return b.s - a.s;
                }
                });
        int f = k - 1;
        int la = k - 1;
        Team p = l.get(k - 1);
        while (la < n && l.get(la).s == p.s && l.get(la).t == p.t) la++;
        while ( f >= 0 && l.get(f).s == p.s && l.get(f).t == p.t) f--;
        out.println(la - f - 1);
    }

  static   class Team {
        int s;
        int t;
        public Team(int a, int b) { s = a; t = b; }
    }



}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A
{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = null;

    private void solve() throws IOException
    {
        int n = nextInt();
        int k = nextInt();
        int p[] = new int[n];
        int t[] = new int[n];
        for(int i = 0; i < n; i++)
        {
            p[i] = nextInt();
            t[i] = nextInt();
        }
        
        for(int i = 0; i < n; i++)
        {
            for(int j = i + 1; j < n; j++)
            {
                if(p[i] < p[j] || (p[i] == p[j] && t[i] > t[j]))
                {
                    int tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                    tmp = t[i];
                    t[i] = t[j];
                    t[j] = tmp;
                }
            }
            
        }
        
        int pN = p[k - 1];
        int tN = t[k - 1];
        int counter = 0;
        for(int i = 0; i < n; i++)
        {
            if(p[i] == pN && t[i] == tN)
            {
                counter++;
            }
            
        }
        
        System.out.println(counter);
    }

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

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

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

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

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