Lazy Running

4개 체크포인트가 이루는 고리에서 p2에서 출발해 p2로 돌아오며 총 이동 거리가 K 이상이 되는 가장 짧은 경로를 구한다.

보통7그래프최단 경로수학아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

In HD University, you have to be able to run around the campus 24 times in a row: otherwise, you will fail the physical education exam and get expelled from the university. According to the rules, you must keep your speed, and your total running distance should be at least KK meters.

There are four checkpoints in the campus, labeled as p_1p\_1, p_2p\_2, p_3p\_3 and p_4p\_4. Every time you pass a checkpoint, you should swipe your card, and the distance between this checkpoint and the last checkpoint you passed will be added to your total distance.

The system regards the four checkpoints as a circle: from checkpoint p_ip\_i, you can only run to one of its neighbors, p_i1p\_{i - 1} or p_i+1p\_{i + 1}; p_1p\_1 and p_4p\_4 are also neighbors of each other. You can run along a straight or curved line between neighboring checkpoints, but it makes no difference for the system: only the distance between checkpoints is taken into account.

Checkpoint p_2p\_2 is the nearest to the dormitory, so Little Q always starts and ends running at this checkpoint. Please write a program to help Little Q find the shortest path such that the total running distance taken into account by the system is at least KK meters.

입력

The first line of the input contains five integers KK, d_1,2d\_{1, 2}, d_2,3d\_{2, 3}, d_3,4d\_{3, 4} and d_4,1d\_{4, 1} denoting the required distance and the distances between every pair of neighboring checkpoints (1K10181 \leq K \leq 10^{18}, 1d31041 \leq d \leq 3 \cdot 10^4).

출력

Print a single line containing a single integer: the length of the shortest path.