// yukicoder: No.817 Coin donation // 2019.6.16 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } #define INF 1000000000 typedef struct { int a, b; } T; T t[100005]; int main() { int i, N, K, s; int l, r, m; N = in(), K = in(); for (i = 0; i < N; i++) t[i].a = in(), t[i].b = in(); // バイナリサーチ l = 0, r = INF; while (l < r) { m = (l + r) >> 1, s = 0; for (i = 0; i < N; i++) if (t[i].a <= m) { if (t[i].b <= m) s += t[i].b - t[i].a + 1; else s += m - t[i].a + 1; if (s > K) break; } if (s == K) { l = m; break; } if (s < K) l = m+1; else r = m; } printf("%d\n", l); return 0; }