Largest monetary amount impossible to make with two types of coin Suppose we have two different types of coin which are worth relatively prime positive integer amounts. In this case, it is possible to make change for all but finitely many quantities. Your job is to find the largest amount that cannot be made with these two types of coin.

Task

Input: A pair of relatively prime integers \$(a,b)\$ such that \$1&lt;a&lt;b\$.

Output: The largest integer that cannot be expressed as \$ax+by\$ where \$x\$ and \$y\$ are nonnegative integers.

Scoring:

This is code golf so shortest answer in bytes wins.

Example:

Input \$(3,11)\$ 

\$4\cdot 3- 1\cdot 11=1\$, so if \$n\geq 22\$ we can write \$n=q\cdot 3 + 2\cdot 11 +r\$ where \$q\$ is the quotient and \$r\in\{0,1,2\}\$ the remainder after dividing \$n-22\$ by \$3\$. The combination \$(q+4r)\cdot 3 + (2-r)\cdot 11 = n\$ is a nonnegative combination equal to \$n\$. Thus the answer is less than \$22\$. We can make \$21=7\cdot 3\$ and \$20=3\cdot 3 + 1\cdot 11\$ but it's impossible to make \$19\$ so the output should be \$19\$.

Test Cases:

[ 2,  3] =&gt; 1

[ 2,  7] =&gt; 5

[ 3,  7] =&gt; 11

[ 3, 11] =&gt; 19

[ 5,  8] =&gt; 27

[ 7, 12] =&gt; 65

[19, 23] =&gt; 395

[19, 27] =&gt; 467

[29, 39] =&gt; 1063

[ 1,  7] =&gt; error / undefined behavior (inputs not greater than one)

[ 6, 15] =&gt; error / undefined behavior (not relatively prime).

[ 3,  2] =&gt; error / undefined behavior (3 &gt; 2)

[-3,  7] =&gt; error / undefined behavior (-3 &lt; 0)
J, 7,6 3 bytes

-1 byte thanks to FrownyFrog ! 

-3 bytes thanks to Grimmy!

*-+


Try it online!

     -    subtract
      +   the sum of the arguments
    *     from their product