Snakebird

Interview

Time limit1sMemory limit128 MB

Summary
Given N fruits at heights h_i and a snake of length L, grow by eating any fruit of height at most the current length and output the maximum length reached.
Level

Medium4 of 10

Topics
Greedy, Sorting, Simulation
Solved
No attempts yet

Problem

The snakebird is a cute creature that resembles a mix of a snake and a bird.

The snakebird's main food is fruit, and eating one fruit increases its length by 1.

The fruits hang at fixed heights above the ground, and the height of the i-th fruit (1 ≤ i ≤ N) is hi.

The snakebird can eat fruits whose height is less than or equal to its own length.

Given the snakebird's initial length L, find the maximum length it can reach by eating fruits.

Input

The first line gives the number of fruits N (1 ≤ N ≤ 1,000) and the snakebird's initial length as an integer L (1 ≤ L ≤ 10,000).

The second line gives the integers h1, h2, ..., hN (1 ≤ hi ≤ 10,000).

Output

Print the snakebird's maximum length on the first line.

Examples2

  1. Example 1

    Input
    3 10
    10 11 13
    Expected output
    12
  2. Example 2

    Input
    9 1
    9 5 8 1 3 2 7 6 4
    Expected output
    10