You finally arrive at your dream ski resort after saving up cash for decades. As this vacation was so expensive, you want to spend the maximum amount of time skiing, which means minimizing time on ski lifts.
The mountain is served by many ski lifts. You have studied the map extensively and wrote down your options for taking lifts to the summit of the mountain. Some of these options might involve riding multiple ski lifts. You have also done research on the time it takes to ride each ski lift, in minutes.
Please find the fastest possible time, in minutes, to ascend from the base of the mountain to the summit using one of these ski lift routes.
The first line will consist of an integer , the number of ski lift routes you can take to get up the mountain.
The next lines will each describe one of the ski lift routes. The first number in each line will be an integer , indicating that this route involves taking different lifts. This will be followed by integers, representing the travel time for each of the ski lifts. None of the travel times for each individual lift will exceed .
Please output one integer, the time required for the shortest ski lift route, in minutes, to get you to the summit.
3 1 10 3 3 5 3 2 1 8
Explanation for Sample Output
The input describes 3 ways to get up the mountain. The first uses one lift that takes 10 minutes. The second uses three lifts, taking 3, 5 and 3 minutes, for a total trip of 11 minutes. The third uses two lifts, taking 1 and 8 minutes, for a total trip of 9 minutes. 9 minutes is the shortest option.