#JSUTFPC2025J. All Winner —— 全胜者

All Winner —— 全胜者

Statement

There are NN teams participating in the chess team competition. Each team consists of MM players. The competition adopts a round-robin system, and a total of N(N1)2\frac{N(N-1)}{2} matches will be played. In each match, the MM players from both teams will be randomly paired for a game, and a winner will be determined in each game. After all matches are over, each player will have played exactly N1N-1 games. If a player wins all games, they will receive the undefeated award. Please find the maximum number of players who can possibly receive the undefeated award.

Input

The input consists of a single line containing two space-separated integers NN and MM, indicating that there are NN teams and each team has MM players (2N1092 \leqslant N \leqslant 10^9, 1M1091 \leqslant M \leqslant 10^9).

Output

Output a single number tt representing the maximum number of players who can potentially win the undefeated award.

Samples

3 3
4
1 1
1

Notes

For the 11st test case, assume that there are 33 teams participating in the competition.

  1. Team TT: players T1,T2,T3T_1, T_2, T_3;
  2. Team WW: players W1,W2,W3W_1, W_2, W_3;
  3. Team RR: players R1,R2,R3R_1, R_2, R_3;

The results of the competition may be as follows:

  • Team TT vs. Team WW :
    • T1T_1 vs. W1W_1, W1W_1 wins
    • T2T_2 vs. W2W_2, W2W_2 wins
    • T3T_3 wins against W3W_3
  • Team TT vs. Team RR
    • T1T_1 wins against R3R_3
    • T2T_2 vs. R1R_1, R1R_1 wins
    • T3T_3 wins against R2R_2
  • Team WW vs. Team RR
    • W1W_1 vs. R3R_3, R3R_3 wins
    • W2W_2 vs. R2R_2, R2R_2 wins
    • W3W_3 wins against R1R_1

At this time, only player T3T_3 from team TT won the undefeated award. In this example, the maximum number of players who could potentially win the undefeated award is 44.