시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 1 1 1 100.000%

문제

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 $K$ meters.

There are four checkpoints in the campus, labeled as $p_1$, $p_2$, $p_3$ and $p_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_i$, you can only run to one of its neighbors, $p_{i - 1}$ or $p_{i + 1}$; $p_1$ and $p_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_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 $K$ meters.

입력

The first line of the input contains five integers $K$, $d_{1, 2}$, $d_{2, 3}$, $d_{3, 4}$ and $d_{4, 1}$ denoting the required distance and the distances between every pair of neighboring checkpoints ($1 \leq K \leq 10^{18}$, $1 \leq d \leq 3 \cdot 10^4$).

출력

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

예제 입력 1

2000 600 650 535 380

예제 출력 1

2165