jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	n := scanInt()
	type music struct {
		s string
		t int
	}
	ms := make([]music, n)
	for i := range ms {
		ms[i].s, ms[i].t = scanString(), scanInt()
	}
	x := scanString()

	isSleep := false
	ans := 0
	for _, m := range ms {
		if m.s == x {
			isSleep = true
			continue
		}

		if isSleep {
			ans += m.t
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import "fmt"

func main() {
	// Code for A - Falling Asleep
	var N int
	fmt.Scan(&N)
	s := make([]string, N)
	t := make([]int, N)
	var sum int
	ans := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&s[i], &t[i])
		sum += t[i]
		ans[i] = sum
	}

	var X string
	fmt.Scan(&X)

	for i := 0; i < N; i++ {
		if X == s[i] {
			fmt.Println(sum - ans[i])
			break
		}
	}
}
//  [ruby]
n = gets.to_i
title = []
sec = []
for i in 0..n-1 do
  a,b = gets.split(" ")
  title.push(a)
  sec.push(b.to_i)
end
x = gets.chomp
flag = false
cnt = 0
for i in 0..n-1 do
  if flag then
    cnt += sec[i]
  elsif x==title[i] then
    flag = true
  end
end
puts(cnt)
//  [ruby]
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end

N = line[0][0].to_i
X = line[N+1][0]

songs = []
for i in 1..N do
  songs.push(line[i][0])
end
x_id = songs.index(X) + 1

answer = 0
for i in (x_id+1)..N do
  answer += line[i][1].to_i
end

print answer
//  [ruby]
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
st=array(N)
N.times do|i|
    st[i]=get
    st[i][1]=st[i][1].to_i
end
X=gets.chomp
flag=false
ans=0
N.times do|i|
  if flag 
      ans+=st[i][1]
  elsif st[i][0]==X
      flag=true
  end
end
puts ans
//  [ruby]
n = gets.to_i
num = 0
a = []
n.times do |i|
  s,t = gets.split
  a << [s, t.to_i]
end
x = gets.chomp
flag_cnt = false
a.each do |b|
  if flag_cnt
    num += b[1]
  else
    flag_cnt = true if b[0] == x
  end
end
puts num
//  [ruby]
n = gets.chomp.to_i
titles = []
seconds = []
n.times do
    a, b = gets.chomp.split
    titles << a
    seconds << b.to_i
end
x = gets.chomp
ans = 0
count_flag = false
n.times do |i|
    ans += seconds[i] if count_flag
    count_flag = true if x == titles[i]
end
puts ans
//  [ruby]
n = gets.to_i
st = n.times.map{gets.split.map(&:chomp)}
x = gets.chomp

sum = 0
check = false
st.each do |s, t|
  sum += t.to_i if check
  check = true if s == x
end

puts sum
//  [rust]
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(String, u32); n],
        x: String,
    }
    let mut ans = 0;
    for (s, t) in p.into_iter().rev() {
        if s == x {
            break;
        }
        ans += t;
    }
    println!("{}", ans);
}

fn main() {
    run();
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:[(String,usize);a],
    m:String,
    }
    let mut x=0;
    let mut z=0;
    for i in 0..a {
        if x==1{
            z+=b[i].1
        }
        if b[i].0==m {x=1;}
    }
    println!("{}",z)
}
//  [swift]

import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readIntPair() -> (a: Int, b: Int) {
    let x = readInts()
    return (a: x[0], b: x[1])
}

func readStrings() -> [String] {
    return Array(readLine()!.split(separator: " ").map { String($0) })
}


struct Music {
    var title: String
    var time: Int
}

var list: [Music] = []
let n = readInt()
for _ in 0..<n {
    let tokens = readStrings()
    list.append(Music(title: tokens[0], time: Int(tokens[1])!))
}
let s = readLine()!

var sleeping: Bool = false
var spend: Int = 0
for m in list {
    if sleeping {
        spend += m.time
    } else {
        if s == m.title {
            sleeping = true
        }
    }
}
print(spend)
//  [typescript]
import { log } from 'util'

{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [N] = r.nn()
    const s: string[] = []
    const t: number[] = []

    for (let i = 0; i < N; i++) {
      const l = r.ss()

      s.push(l[0])
      t.push(Number(l[1]))
    }
    const x = r.s()

    let found = false
    let sum = 0

    for (let i = 0; i < N; i++) {
      if (found) {
        sum += t[i]
      }
      found = found || x === s[i]
    }

    return sum
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}
//  [python]
import numpy as np
import math

# K = int(input())
# A, B = map(int, input().split())
# A = list(map(int, input().split()))

N, x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

tot = 0
for i, a in enumerate(A):
    tot += a
    if tot > x:
        print(i)
        exit(0)
    elif tot == x:
        print(i+1)
        exit(0)

print(len(A)-1)
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
n,x = map(int, input().split())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]

a=sorted(a)

#print(a)
answer=0
for i in range(n-1):
    if x >= a[i]:
        answer += 1
        x -= a[i]
#        print(x,a[i])
    else:
        break
if x == a[n-1]:
    answer += 1
print(answer)
//  [python]
import numpy as np

N, x = list(map(int, input().split()))
a = np.asarray(list(map(int, input().split())))
a = np.sort(a)
s = 0
for i in range(1, N):
    if np.sum(a[:i]) <= x:
        s += 1
if np.sum(a) == x:
    s += 1
print(s)
//  [java]
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		int n=s.nextInt();
		int x=s.nextInt();
		int[]a=INTS(n).sorted().toArray();
		
		int r=0;
		for(int i=0;i<n;++i) {
			if(x>=a[i]) {
				++r;
				x-=a[i];
			}else {
				x=0;
				break;
			}
		}
		System.out.println(x==0?r:r-1);
	}

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

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return new Range(i);
	}
	Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int n){
		return REP(0,n-1);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int t;
	Supplier<T> supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}
}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] line = br.readLine().split(" ");
        int N = Integer.parseInt(line[0]);
        int x = Integer.parseInt(line[1]);
        List<Integer> list = Arrays.stream(br.readLine().split(" "))
            .map(Integer::parseInt)
            .sorted()
            .collect(Collectors.toList());
        int output = 0;    
        for (int num: list) {
            if (x >= num) {
                x -= num;
                output++;
            } else {
                break;
            }
        }
        if (list.size() == output && x > 0) {
            output--;
        }
        out.println(output);
        out.close();
    }
}
//  [java]
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long x = Long.parseLong(sc.next());
        Long[] a = new Long[n];
        Arrays.setAll(a, i -> Long.parseLong(sc.next()));
        sc.close();

        // 主処理
        int result = 0;
        long sum = Arrays.stream(a).mapToLong(i -> i).sum();
        if (x < sum) {
            Arrays.sort(a);
            long num = 0;
            for (int i = 0; i < a.length; i++) {
                num += a[i];
                if (num <= x) {
                    result++;
                }
            }
        } else if (sum < x) {
            result = n - 1;
        } else {
            result = n;
        }

        // 出力
        System.out.println(result);
    }
}
//  [cpp]
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i, b, n) for(int i=b;i<(int)n;i++)
#define rep(i, n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it, o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;


int main() {
    ll n, sum;
    cin >> n >> sum;

    vector<ll> a(n);
    ll all = 0;
    rep(i, n){
        cin >>a[i];
        all += a[i];
    }
    if(all == sum){
        cout << n <<endl;
        return 0;
    }


    ll ans = 0;
    rep(skip, n) {
        vector<ll> V(n + 1);
        rep(i, n + 1)V[i] = -1;
        V[0] = sum;
        rep(i, n) {
            if(i == skip)continue;
            vector<ll> next = V;
            rep(j, n) {
                next[j + 1] = max(next[j + 1], V[j] - a[i]);
                if (next[j + 1] >= 0)ans = max(ans, ll(j + 1));
            }
            V = next;
            rep(i, n + 1) {
                cerr << next[i] << ' ';
            }
            cerr << endl;
        }
    }
    cout << ans <<endl;
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int64 N, x;
   int64 a[111];
   cin >> N >> x;
   rep (i, N) {
      cin >> a[i];
   }
   sort(a, a+N);

   int64 ans = 0;
   rep (i, N) {
      x -= a[i];
      if (x < 0) break;
      if (i+1==N && x != 0) break;
      ans++;
   }
   cout << ans << endl;

   return 0;
}
//  [cpp]
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define amen ;
#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    int n, x;
    cin >> n >> x;
    vector <int> v(n);
    for (auto &it : v)
        cin >> it;
    sort(all(v));
    int ans = 0;
    for (auto it : v)
    {
        if (it <= x)
        {
            ans++;
            x -= it;
        }
    }
    cout << (ans == n && x ? ans - 1 : ans);
}
//  [c]
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


#include <stdio.h>

#include<stdio.h>

int main(void)
{
	int  i, cnt = 0;
	int  x,a[101],n;

	i_cin2(n,x);
	i_cins(n, a);
	qsort(a,n,sizeof(int),s_asort);
	
	for (i = 0; i < n; i++) {
		if (!a[i]) continue;
		cnt++;
		x -= a[i];
		if (x <= 0)break;
	}
	
	(!x) ? i_cout(cnt) : i_cout(cnt - 1);
	return 0;
}
//  [c]
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


#include <stdio.h>

#include<stdio.h>

int main(void)
{
	int  i, cnt = 0;
	int  x,a[101],n;

	i_cin2(n,x);
	i_cins(n, a);
	qsort(a,n,sizeof(int),s_asort);
	
	for (i = 0; i < n; i++) {
	
		cnt++;
		x -= a[i];
		if (x <= 0)break;
	}
	
	(!x) ? i_cout(cnt) : i_cout(cnt - 1);
	return 0;
}
//  [javascript]
function getLines(input){
	return input.split("\n").map((s)=>s.trim())
}
function parseLine(line){
	return line.split(" ").map((s)=>s.trim());
}
function parseLineToInt(line){
	return line.split(" ").map((s)=>parseInt(s.trim()));
}
// parameter "input" gets all data
function Main(input) {
	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.	
	input = getLines(input).map(parseLineToInt);
	var a = input[1];
	var n=input[0][0];
	var x=input[0][1];
	a.sort((z,t)=>(z-t));
	i=0;
	var ans =0;
	while(x>0 && i<n){
		if(x>=a[i]){
			x-=Math.min(x,a[i++]);
			ans++;
		}else{
			break;
		}
	}
	if(x>0 && i==n)
		ans--;
	console.log(ans);
}
// Don't edit this line!
//Main(require("fs").readFileSync(__dirname+'/in.txt', "utf8"));
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict';

function Main(input) {
  const N = Number(input.split('\n')[0].split(' ')[0]);
  let x = Number(input.split('\n')[0].split(' ')[1]);
  let alist = input.split('\n')[1].split(' ').map(num => Number(num));
  alist.sort((a,b) => a < b ? -1 : 1);
  let aPointer = 0;

  while(aPointer < N) {
    if(x >= alist[aPointer]) {
      x -= alist[aPointer];
      if(aPointer + 1 !== N || x === 0) {
        aPointer++;
      }
     } else {
      break;
    }
  }

  console.log(aPointer);

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var x = o.a();
  var a = o.l();
  a.sort((a,b)=>a-b);
  for(var i = 0; i < n; i++){
    x -= a[i];
    if(x < 0)return i;
  }
  return x ? i-1:i;
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	x := nextInt()
	al := make([]int, n)

	for i := 0; i < n; i++ {
		al[i] = nextInt()
	}
	sort.Ints(al)

	cnt := 0
	for i := 0; i < n-1; i++ {
		if x >= al[i] {
			x -= al[i]
			cnt++
		}
	}
	if x == al[n-1] {
		cnt++
	}
	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func contains(target int, list []int) bool {
	for _, r := range list {
		if target == r {
			return true
		}
	}
	return false
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()

	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextInt64() int64 {
	sc.Scan()

	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func isInteger(x float64) bool {
	return math.Floor(x) == x
}

func Ave(s []int) int {
	val := 0
	for _, i := range s {
		val += i
	}
	return int(val / len(s))
}
func cal(i int) (sum int) {
	for i != 0 {
		sum += i % 10
		i /= 10
	}
	return
}
func max(a []int) (idx int, val int) {
	max := a[0]
	idx = 0
	for j, i := range a {
		if max < i {
			max = i
			idx = j
		}
	}
	return idx, max
}

func draw(i int, a []int) (l []int) {
	// p = a[i]
	for j := i; j < len(a); j++ {
		if j != len(a)-1 {
			a[j] = a[j+1]
		} else if j == len(a)-1 {
			a = a[:len(a)-1]
		}
	}
	return a
}
func abs(i int64) int64 {
	if i < 0 {
		return -i
	}
	return i
}

func f(n int) int {
	if n%2 == 0 {
		return n / 2
	}
	return 3*n + 1
}

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer([]byte{}, math.MaxInt64)
	// a := make([][]int, 3)
	// for i := 0; i < 3; i++ {
	// 	a[i] = make([]int, 3)
	// }
	// for i := 0; i < 3; i++ {
	// 	for j := 0; j < 3; j++ {
	// 		a[i][j] = nextInt()
	// 	}
	// }
	n := nextInt()
	x := nextInt()

	var a []int
	var wa int
	var cnt int
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}

	sort.Ints(a)

	for _, val := range a {
		if wa+val <= x {
			wa += val
			cnt++
		} else {
			fmt.Println(cnt)
			return
		}
	}
	if wa < x {
		fmt.Println(cnt - 1)
	} else if wa == x {
		fmt.Println(cnt)
	}

}
//  [go]
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, x int
	fmt.Scan(&N, &x)

	a := make([]int, N)
	for i:=0; i<N;i++ {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)

	sum, count := 0, 0

	for _, v := range a {
		sum += v

		if sum <= x {
			count++
		}
	}

	if sum < x {
		count--
	}

	fmt.Println(count)
}
//  [ruby]
n,x,*a=`dd`.split.map &:to_i;a.sort!
i=(0...n).find{|i|0>x-=a[i]}
p i ? i : x>0 ? n-1 : n
//  [ruby]
N, x = gets.split.map(&:to_i)
an = gets.split.map(&:to_i)

ans = 0

an.sort.each do |a|
  x = x - a
  ans += 1
  if x == 0
    break
  elsif x < 0
    ans -= 1
    break
  end
end

ans -= 1 if x > 0

puts ans
//  [ruby]
N, x = gets.split.map &:to_i
a = gets.split.map &:to_i
cnt = 0
a.sort.each do |i|
  if x - i < 0
    puts cnt
    exit
  else
    cnt += 1
    x -= i
  end
end
if x == 0
  puts cnt
else
  puts cnt - 1
end
//  [rust]
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      n: usize, x: isize,
      mut aa: [isize; n]
    };

    aa.sort();

    let mut total = x;
    let mut c = 0;
    let sum: isize = aa.iter().sum();

    for i in 0..n {
        if &total >= &aa[i] {
            total -= &aa[i];
            c += 1;
        } else {
            break;
        }
    }

    println!("{}", if c == n && sum != x { c - 1 } else { c });
}
//  [rust]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    mut b:usize,
    mut c:[usize;a],
    }
    c.sort();
    let mut d=0;
    for i in 0..a{
        if b>=c[i]{
            b-=c[i];
            d+=1;
        }
    }
    println!("{}",if d==a&&b!=0{a-1}else{d})
}
//  [rust]
use proconio::input;

fn main() {
    input!{
        n: i64,
        mut x: i64,
        mut a: [i64; n],
    }

    a.sort();

    let mut ans = 0;
    for i in 0..n as usize {
        x -= a[i];
        ans += 1;

        if x <= 0 {
            break;
        }
    }

    if x != 0 {
        ans -= 1;
    }

    println!("{}", ans);
}
//  [python]
from collections import defaultdict
import sys
buf = sys.stdin.buffer


def main():
    n, k = map(int, buf.readline().split())
    AB = map(int, buf.read().split())

    count = defaultdict(int)
    for a, b in zip(AB, AB):
        count[a] += b

    idx = 0
    for num in sorted(count.keys()):
        idx += count[num]
        if idx >= k:
            print(num)
            break


if __name__ == "__main__":
    main()
//  [python]
# s = input()
# n = len(s) - 1
# ans = 0
# for i in range(1 << n):
#     formula = s[0]
#     for j in range(n):
#         if ((i >> j) & 1):
#             formula += '+' + s[j + 1]
#         else:
#             formula += s[j + 1]
#     ans += eval(formula)
# print(ans)
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, k = nm()
    A = [0] * (10 ** 5 + 1)
    for i in range(n):
        a, b = nm()
        A[a] += b

    sum_num = 0
    for i, a in enumerate(A):
        sum_num += a
        if sum_num >= k:
            print(i)
            return


if __name__ == '__main__':
    main()
//  [python]
# https://atcoder.jp/contests/abc061/tasks/abc061_c
import sys

def main():
    n, k = map(int, input().split())
    ans = [0 for _ in range(10**5+1)]
    for x in sys.stdin.readlines():
        a, b = map(int, x.split())
        ans[a] += b

    cnt = 0
    for i in range(10**5+1):
        cnt += ans[i]
        if cnt >= k:
            print(i)
            exit()

if __name__ == "__main__":
    main()
//  [python]
temp=input().split()
N=int(temp[0])
K=int(temp[1])
ab=[[int(j) for j in input().split()] for i in range(N)]

ab.sort()
while ab[0][1]<K:
	K-=ab[0][1]
	del ab[0]
	#print(ab)
print(ab[0][0])
//  [python]
# -*- coding: utf-8 -*-
line = input().split(" ")
n = int(line[0])
k = int(line[1])

l = []
for _ in range(n):
    line = input().split(" ")
    a = int(line[0])
    b = int(line[1])
    l.append([a,b])

l.sort()

while k>0:
    x = l.pop(0)
    k = k-x[1]

print(x[0])
//  [python]
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long k = Long.parseLong(sc.next());
		Map<Integer, Long> m = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			long b = Integer.parseInt(sc.next());
			if (m.get(a) != null) {
				b += m.get(a);
			}
			m.put(a, b);
		}
		long c = 0;
		for (Integer i:m.keySet()) {
			c += m.get(i);
			if (c >= k) {
				System.out.println(i);
				return;
			}
		}
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))
//  [java]
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int n = in.readInt();
	   long k = in.readLong();
	   long range[] = new long[100005]; 
	   for(int i = 0; i<n; i++) {
		   int a = in.readInt();
		   int b = in.readInt();
		   range[a] += b; 
	   }
	  
	   for(int i = 1; i<100005; i++) {   
		   if(k <= range[i]) {
			   System.out.println(i);
			   return; 
		   }
		   k -= range[i]; 
	   }
	}
}

class InputReader {

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

	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();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	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 boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

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

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}
//  [java]
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), n=N;
		double K = sc.nextDouble(), t=0;
		Map<Double, Double> m = new HashMap<Double, Double>();
		Queue<Double> minQueue = new PriorityQueue<Double>();
		while (n-->0) {
			double b = sc.nextDouble(), c = sc.nextDouble();
			if (!m.containsKey(b)) minQueue.add(b);
			m.put(b,m.get(b)==null ? c : m.get(b)+c);
		}
		while (!minQueue.isEmpty()) {
			double k = minQueue.poll();
			if (t==K||t+m.get(k)>=K) {
				System.out.println((int)k); System.exit(0);				
			}
			t+=m.get(k);
		}
		sc.close();		
	}

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

}
//  [java]
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), n=N;
		double K = sc.nextDouble(), t=0;
		Map<Double, Double> m = new HashMap<Double, Double>();
		Queue<Double> minQueue = new PriorityQueue<Double>();
		while (n-->0) {
			double b = sc.nextDouble(), c = sc.nextDouble();
			if (!m.containsKey(b)) minQueue.add(b);
			m.put(b,m.get(b)==null ? c : m.get(b)+c);
		}
		Iterator<Double> i = minQueue.iterator();
		while (i.hasNext()) {
			double k = i.next();
			if (t==K||t+m.get(k)>=K) {
				System.out.println((int)k); System.exit(0);				
			}
			t+=m.get(k);
			i.remove();
		}
		sc.close();		
	}

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

}
//  [java]
import java.util.*;

public class Main {
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();

		Map<Integer, Long> mp = new HashMap<Integer, Long> ();
		ArrayList<Integer> al = new ArrayList<Integer> ();
		while(sc.hasNext()) {
			int a = sc.nextInt();
			long t = sc.nextLong();
			if(mp.containsKey(a)) {
				mp.put(a, mp.get(a)+t);
			}
			else {
				mp.put(a, t);
				al.add(a);
			}
		}
		
		Integer[] ar = al.toArray(new Integer[al.size()]);
		Arrays.sort(ar);
		int i = 0;
		long ttl = mp.get(ar[i]);
		while(ttl<k) {
			i++;
			ttl += mp.get(ar[i]);
		}
		System.out.println(ar[i]);
	}
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline ll getK() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll A[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N = getint(), K =getK();
	rep(i, N) {
		int a = getint();
		A[a] += getint();
	}

	ll kazu = 0;
	int kotae = 1;
	for (; kotae <= 100000; kotae++) {
		kazu += A[kotae];
		if (kazu >= K) break;
	}

	printf("%d", kotae);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef unsigned int uint;
typedef long long int ll;
typedef unsigned long long int ull;

#define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;
#define debugm(m) printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;
#define debugaa(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}
#define debugaar(m,w,h) printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}
#define ALL(v) (v).begin(),(v).end()
#define repeat(l) for(auto cnt=0;cnt<(l);++cnt)
#define upto(l,r) for(auto cnt=l;cnt<=r;++cnt)
#define downto(r,l) for(auti cnt=r;cnt>=l;--cnt)
#define BIGINT 0x7FFFFFFF
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

#define TIME chrono::system_clock::now()
#define MILLISEC(t) (chrono::duration_cast<chrono::milliseconds>(t).count())
namespace {
    std::chrono::system_clock::time_point ttt;
    void tic() { ttt = TIME; }
    void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); }
    std::chrono::system_clock::time_point tle = TIME;
#ifdef __MAI
    void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); }
#else
#define safe_tle(k) ;
#endif
}

#ifdef __MAI //_getchar_nolock
#define getchar_unlocked getchar
#endif
namespace {
    class MaiScanner {
    public:
        template<typename T>
        void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        inline MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
    };
}
MaiScanner scanner;


ll n, kei;

ll vv[101010];

int main() {
    scanner >> n >> kei;

    repeat(n) {
        int a, b;
        scanner >> a >> b;

        vv[a] += b;
    }

    int i;
    for (i = 1; 0 < kei; ++i) {
        kei -= vv[i];
    }

    cout << (i-1) << endl;

    return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	ll N = getint(), K = getint();
	ll S[100001] = {};
	rep(i, N) {
		int a = getint(), b = getint();
		S[a] += b;
	}
	int k;
	for (k = 1; k <= 100000; k++) {
		K -= S[k];
		if (K <= 0) break;
	}
	co(k);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll index_ary[100005];

int search(ll a[], ll x, ll n){
  for(ll i=0; i<n; i++)
    if(a[i] == x)
      return 1;
  return 0;
}

int main() {
  ll n,k;
  cin >> n >> k;
  
  map<ll,ll> mp;
  ll unique_index = 0;
  for(ll i=0; i<n; i++){
    ll x, y;
    cin >> x >> y;
    mp[x] += y;
    if(search(index_ary, x, unique_index)==0){
      index_ary[unique_index] = x;
      unique_index++;
    }
  }
  
  sort(index_ary, index_ary + unique_index);
  
  ll counter = 0;
  for(int i=0; i<unique_index; i++){
    counter += mp[index_ary[i]];
    if (counter > k-1){
      cout << index_ary[i] << endl;
      return 0;
    }
  }
}
//  [cpp]
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
using namespace std;

int main(){
    int n;
    long long m;
    cin>>n>>m;
    int a,b;
    vector<int> card;
    long long num[100005]={};
    for(int i=0; i<n; i++){
        cin>>a>>b;
        vector<int>::iterator citer = find( card.begin(),card.end() , a );
        if( citer==card.end() ){
            card.push_back(a);
        }
        num[a]+=b;
    }
    sort(card.begin(), card.end());
    long long key=m;
    for(int i=0; i<card.size();i++){
         key-=num[card[i]];
        if(key<=0){
            cout<<card[i]<<endl;
            break;
        }

    }
    return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k,sum=0,che,sums=0;cin>>n>>k;
  long long int a[n],b[n];
  vector<long long int> v(n),w={};
  for(long long int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(long long int i=0;i<n;i++) v.at(i)=a[i];
  sort(v.begin(),v.end());
  w.push_back(v.at(0));
  che=v.at(0);
  for(long long int i=1;i<n;i++){
    if(che!=v.at(i)){
      w.push_back(v.at(i));
      che=v.at(i);
    }
  }
  for(int i=0;i<n;i++) sums+=b[i];
  if(k<sums/2){ 
  for(long long int i=0;i<w.size();i++){
    for(long long int j=0;j<n;j++){
      if(a[j]==w.at(i)){
        sum+=b[j];
      }
    }
    if(sum>=k){
      cout<<w.at(i)<<endl;
      break;
    }
  }
  }
  else{
    for(long long int i=w.size()-1;i>=0;i--){
    for(long long int j=0;j<n;j++){
      if(a[j]==w.at(i)){
        sum+=b[j];
      }
    }
    if(sum>=sums+1-k){
      cout<<w.at(i)<<endl;
      break;
    }
  }
  }
}
//  [c]
long long n,k,a,s[2<<16];main(b){for(scanf("%*d%lld",&k);~scanf("%d%d",&a,&b);)s[a]+=b;for(;k>0;)k-=s[++n];printf("%d\n",n);}
//  [c]
long long n,k,a,s[123456];main(b){for(scanf("%*d%lld",&k);~scanf("%d%d",&a,&b);)s[a]+=b;for(;k>0;)k-=s[++n];printf("%d\n",n);}
//  [c]
#include<stdio.h>
int main(){
  long int x[100001];
  long int n,k,i,a,b;
  scanf("%ld%ld",&n,&k);
  for(i=0;i<100001;i++)x[i]=0;
  for(i=0;i<n;i++){scanf("%ld%ld",&a,&b);x[a]+=b;}
  for(i=0;i<100001;i++){k-=x[i];if(k<=0){printf("%ld",i);return 0;}}
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}


// min
int main(void){
  long int n, k;
  long int ans = 0;
  long int a[100001];
  long int b[100001];
  long long int cnt[100001] = {0};

  // nとkを取得して
  scanf("%ld%ld", &n, &k);

  // a[], b[] も取得する
  for(long int i = 0; i < n; i++){
    scanf("%ld%ld", &a[i], &b[i]);
    // どの値が何個あるか格納しておく
    cnt[a[i]] += b[i];
  }

  /* 
  for(long int i = 0; i < n; i++){
    for(long int j = 0; j < b[i]; j++){
      cnt[a[i]]++;
    }
  } 
  */
  //  qsort(c, n, sizeof(long long int), compare_int);
  //  qsort(r, n, sizeof(long int), compare_int_small)  //  fprintf(stderr, "l[0] = %ld  r[0] = %ld\n", l[0], r[0]);

  long long int j = 0;
  while(k > 0){
      fprintf(stderr, "j = %lld\n", j);
    
      //    if(k - cnt[j] >= 0){
      fprintf(stderr, "if j = %lld\n", j);
      ans = j;
      k -= cnt[j];
      //    }else{
      //      ans = j;
      fprintf(stderr, "else j = %lld\n", j);
      //    }
    j++;
  }
  
  
  printf("%ld\n", ans);
  
  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}


// min
int main(void){
  long int n, k;
  long int ans = 0;
  long int a[100001];
  long int b[100001];
  long long int cnt[100001] = {0};

  // nとkを取得して
  scanf("%ld%ld", &n, &k);

  // a[], b[] も取得する
  for(long int i = 0; i < n; i++){
    scanf("%ld%ld", &a[i], &b[i]);
    // どの値が何個あるか格納しておく
    cnt[a[i]] += b[i];
  }

  /* 
  for(long int i = 0; i < n; i++){
    for(long int j = 0; j < b[i]; j++){
      cnt[a[i]]++;
    }
  } 
  */
  //  qsort(c, n, sizeof(long long int), compare_int);
  //  qsort(r, n, sizeof(long int), compare_int_small)  //  fprintf(stderr, "l[0] = %ld  r[0] = %ld\n", l[0], r[0]);

  long long int j = 0;
  // kが0以下になった時の値が答えになる
  while(k > 0){
    fprintf(stderr, "j = %lld\n", j);
    ans = j;
    k -= cnt[j];
    j++;
  }
  
  
  printf("%ld\n", ans);
  
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>

struct pair {
    long x;
    long n;
};

int cmp(const void *a,const void *b)
{
  // return *(int*)a-*(int*)b;
   return (*(struct pair*)a).x - (*(struct pair*)b).x;
}



int main(void)
{
  // int n, k, a[2][100000], i;
   int n, i;
   long k;
   struct pair a[100000];

   scanf("%d%ld",&n,&k);
   for(i=0;i<n;i++)
//      scanf("%d%d",&a[0][i],&a[1][i]);
      scanf("%ld%ld",&a[i].x,&a[i].n);

   qsort(a  ,n,sizeof(struct pair),cmp);

   for(i=0;i<n;i++){
      k-=a[i].n;
      if(k<=0){
         printf("%ld\n",a[i].x);
         return 0;
      }
   }
}
//  [javascript]
'use strict'
function main(input) {
    const tmp = input.split('\n');
    const NK = tmp.shift().split(' ').map((elem) => parseInt(elem, 10));
    const N = NK[0];
    const K = NK[1];

    let bucket = new Array(100001).fill(0);
    for (let ab of tmp) {
        const a = parseInt(ab.split(' ')[0], 10);
        const b = parseInt(ab.split(' ')[1], 10);
        bucket[a] += b;
    }


    let count = 0;
    for (let i = 0; i < bucket.length; i++) {
        count += bucket[i];
        if (count >= K) {
            console.log(i);
            break;
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));