Eating Pi


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C++, Java, Python

Tony has been invited out to eat. He's quite hungry and decides to visit Ritisha's Pie Emporium, famous for its rotating pie a magnificent dessert made up of several slices of different sizes arranged in a perfect circle.

What makes this pie truly special, however, is that whenever Tony eats a slice, an identical slice instantly reappears in the same spot. This means he could, in theory, eat forever.

But Ritisha has three rules:

  1. You cannot eat the same slice twice in a row.
  2. You can only eat a slice that is directly clockwise or anticlockwise of the one you just ate.
  3. If you start a slice, you must finish it

each slice costs the same, no matter its size. Tony is on a budget and wants to eat just enough to exactly satisfy his hunger, represented by a target number.

Starting from the 1st slice given, determine the fewest number of slices Tony must eat to reach exactly his target hunger level, or state that it's impossible.

Input

The first line contains two integers n (2 \leq n \leq 1000) and q (1 \leq q \leq 1000) the number of different slices , starting hunger level the next line contains n integers the sizes of each slice of pie f_i (1 \leq f_i \leq q)

Output

Output the minimum number of slices Tony can eat to satisfy his hunger if there is no way to satisfy his hunger output -1

Clarifcations

  • you must eat the 1st slice offered

Example

Input 1
4 8
1 2 4 3
Output 1
3

  • starting hunger: 8
  • eat slice 0
  • hunger: 7
  • turn clockwise
  • eat slice 3
  • hunger: 3
  • turn clockwise
  • eat slice 2
  • hunger: 0
  • we ate 3 slices output 3
Input 2
5 7
3 1 4 1 5
Output 2
3

  • starting hunger: 7
  • eat slice 0
  • hunger: 4
  • turn anticlockwise
  • eat slice 1
  • hunger: 3
  • turn clockwise
  • eat slice 0
  • hunger: 0
  • we ate 3 slices output 3
Input 3
4 15
2 4 6 10 12
Output 3
-1
  • there is no way to reach 15

Comments

There are no comments at the moment.