https://www.acmicpc.net/problem/2805
const fs = require('fs')
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n')
const [N, M] = input[0].split(' ').map(Number)
const A = input[1].split(' ').map(Number)
let [l, r] = [0, Math.max(...A)]
while (l < r) {
const mid = Math.ceil((l + r) / 2)
let x = 0
for (let i = 0; i < N; i++) if (A[i] > mid) x += A[i] - mid
// 가져갈 수 있는 나무의 높이 x 초기화
x >= M ? (l = mid) : (r = mid - 1)
} // 이분 탐색으로 높이의 최댓값 확인
console.log(l)