#P12322. Escape the Secret Realm

    ID: 14421 Type: Default 1000ms 256MiB

Escape the Secret Realm

Escape the Secret Realm

During an interstellar journey, Blue accidentally stumbles into a mysterious realm on a number line. The entrance to the realm is at position \(1\) (Blue's starting point) and the exit lies at position \(L\). In each move, Blue may select any two positive integers \(x\) and \(y\) from the set \(\{a_1, a_2, \dots, a_n\}\) and instantly teleport \(x+y\) units to the right. However, due to the finite size of the realm, if Blue's current position is \(p\), the new position will be computed as

\[ (p + x + y - 1) \bmod L + 1 \]

Blue escapes the realm once his position is exactly \(L\). Determine the minimum number of teleports needed to exit the realm. If it is impossible to reach the exit, output \(-1\).

inputFormat

The input consists of two lines:

  • The first line contains two integers \(n\) and \(L\) (the number of available integers and the exit position of the realm, respectively).
  • The second line contains \(n\) positive integers \(a_1, a_2, \dots, a_n\) which represent the available numbers.

outputFormat

Output a single integer: the minimum number of teleports needed for Blue to reach the exit position \(L\). If it is not possible, output \(-1\).

sample

1 5
2
1