Choose distinct dice values from 1 to 6 so that Alice's die is strictly larger than Bob's and the score difference is as small as possible.
Problem
You are given two integers describing the values shown on two dice. You may increase either die's value to any value from 1 to 6, but you cannot decrease it.
Your task is to determine the minimum total number of increments needed to make the first die strictly greater than the second die.
If it is already impossible to make the first die strictly greater than the second die under the dice limits, report that no valid adjustment exists.
Goal
Find the smallest change needed so that:
- both final values stay in the range ,
- the first value becomes strictly larger than the second value,
- and the total increase is minimized.
Input Format
- Two integers and — the current values on the two dice.
- Both values are in the range $1 to \6$.
Output Format
- Print the minimum total number of increments needed to make .
- If it cannot be done, print
-1.
Constraints
- Final values must remain between $1 and \6$
- Only increments are allowed
Example 1
Input
1 1
Output
1
Explanation
Increase the first die to 2. Then 2 > 1, and the total increment is 1.
Example 2
Input
4 2
Output
0
Explanation
The first die is already greater than the second die, so no change is needed.
Show 1 more example
Example 3
Input
2 6
Output
-1
Explanation
The second die is already at the maximum value, and the first die cannot exceed 6 using increments only.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.