#K53922. Minimum Segments Path
Minimum Segments Path
Minimum Segments Path
You are given a target integer \(n\) and \(m\) different types of flower segments. Each segment type has a height \(h_i\). You can use each segment any number of times. Your task is to determine the minimum number of segments required to form a path whose total height is exactly \(n\). If it is impossible to achieve the sum \(n\) using the provided segments, output \(-1\).
inputFormat
The input consists of two lines. The first line contains two space-separated integers \(n\) and \(m\), where \(n\) is the target sum and \(m\) is the number of available segment types. The second line contains \(m\) space-separated integers \(h_1, h_2, \dots, h_m\), which represent the heights of each segment type.
outputFormat
Output a single integer representing the minimum number of segments required to sum exactly to \(n\). If it is not possible to form such a sum, output \(-1\).
## sample10 3
2 3 7
2