#include #include #include #include typedef char SINT8; typedef unsigned char UINT8; typedef short SINT16; typedef unsigned short UINT16; typedef int SINT32; typedef unsigned int UINT32; typedef long long SINT64; typedef unsigned long long UINT64; typedef double DOUBLE; #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define ABS(a) ((a)>(0)?(a):-(a)) #define REP(i,n) for(int (i)=0;(i)<(n);(i)++) using namespace std; int main() { SINT32 N = 0; SINT32 M = 0; SINT32 cntA = 1; SINT32 cntB = 0; SINT32 cntM = 0; SINT32 ANS = 0; cin >> N; cin >> M; vector DATAA(N); vector DATAB(N); for (SINT32 i = 0; i < N; i++) { cin >> DATAA[i]; cin >> DATAB[i]; } sort(DATAA.begin(),DATAA.end()); DATAA.emplace_back(1000000001); //後ろに追加 sort(DATAB.begin(),DATAB.end()); SINT32 Plus = 1; for (SINT32 i = DATAA[0]; i < 1000000001; i++) { while (DATAA[cntA] == i+1) { Plus++; cntA++; } cntM = cntM + Plus; if (cntM >= M) { ANS = i+1; break; } while (DATAB[cntB] == i+1) { Plus--; cntB++; } // cout << Plus << endl; } cout << ANS<< endl; return 0; } // sort(DATA.begin(),DATA.end()); // sort(DATA.begin(),DATA.end(),std::greater()); // __gcd(ANS,DATA[i]); // // DATA.emplace_back(BUF); //後ろに追加 // DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end()); // vector> DP(N,vector(3)); //2次元配列 /* SINT32 M = 3; vector> DATA2(M); for (SINT32 i = 0; i < M; i++) { cin >> DATA2[i].first; cin >> DATA2[i].second; } sort(DATA2.begin(),DATA2.end()); cout << DATA2[0].first << endl; cout << DATA2[0].second << endl; */ // vector>> DATA(M); // cin >> DATA[i].first; // cin >> DATA[i].second.first; // cin >> DATA[i].second.second; // APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin(); // BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin(); /* 文字列回転 string N; cin >> N; N = N[N.length()-1] + N.substr(0,N.length()-1); */