eolymp
bolt
Try our new interface for solving problems
Problems

Casting

Casting

In theater n actors are working. It is known that among them there are a tall, b blue-eyed and c blond. For the main role in a new performance director requires only one high blue-eyed blond. To plan the time to talk with each such actor from theater troupe, the director needs to know what is the maximum or the minimum number of artists working in the theater appropriate for the role.

Given the numbers n, a, b and c, define the minimum and maximum number of artists with whom the director should talk.

Input

The first line contains a number that specifies the minimum or maximum number of actors need to find in this test. This number could take the following values:

  • 1, if in this test required to determine the minimum number of actors;
  • 2, if in this test required to determine the maximum number of actors.

Second line contains four integers: n, a, b, с (1n10000, 0a, b, cn).

Output

Print one number - the minimum or maximum (depending on the input data) number of actors who can claim a major role in the new play.

Explanation

In the first example, since we have 3 high actors, the main role can not go to more than three people.

In the second example all actors are blond and all but one are blue-eyed. Then, among the three highest actors there are at least two blue-eyed (and, naturally, they are blond). Consequently, at least two actors exactly suited for the leading role in a new play.

Time limit 1 second
Memory limit 128 MiB
Input example #1
2
5 3 4 5
Output example #1
3
Input example #2
1
5 3 4 5
Output example #2
2
Input example #14
1
4321 321 1253 2247
Output example #14
0
Source 2012 XIII Al Russia School Informatics Olympiad, Third regional round, Sankt-Peterburg, Problem А