A smallest different sequence (SDS) is a sequence
of positive integers created as follows: . For , , where is the smallest positive integer
not yet appearing as a value in the sequence or as a difference
between two values already in the sequence. For example, if
, then since
is the smallest number
not in our sequence so far, . Likewise , since and are already accounted for, either
as values in the sequence, or as a difference between two
values. Continuing, we have , and accounted for, leaving
as our next smallest
difference; thus .
The next few values in this SDS are For
a positive integer ,
you are to determine where in the SDS first appears, either as a value
in the SDS or as a difference between two values in the SDS. In
the above SDS,
and first appear in
step .
Input
Input consists of a single line containing two positive
integers
().
Output
Display the smallest value such that the sequence
either contains as a
value in the sequence or as a difference between two values in
the sequence. All answers will be .
Sample Input 1 |
Sample Output 1 |
1 5
|
4
|
Sample Input 2 |
Sample Output 2 |
1 12
|
4
|
Sample Input 3 |
Sample Output 3 |
5 1
|
2
|