P23740 [AtCoder] [ABC040A] Red Red Red Red Blue
入门
题目描述

Problem Description

There are $ n $ blocks arranged in a row. Only the $ x $-th block from the front is blue, and the rest are all red.

Takahashi wants to bring the blue block to the end of the row (either the 1st or the $ n $-th position) by swapping adjacent blocks several times.

Determine the minimum number of operations required.

Input Format

The input is given from the standard input in the following format:

$ n $ $ x $

Output Format

Output the minimum number of operations required as an integer in one line.

Sample Input and Output

Sample Input #1

5 2

Sample Output #1

1

Sample Input #2

6 4

Sample Output #2

2

Sample Input #3

90 30

Sample Output #3

29

Notes/Hints

Constraints

  • $1 \leq n \leq 100$
  • $1 \leq x \leq n$

Sample Explanation 1

Initially, the 2nd block from the front is blue, so swapping it with the 1st block brings the blue block to the end.

Sample Explanation 2

  • First, swap the 4th and 5th blocks.
  • Then, swap the 5th and 6th blocks to bring the blue block to the end.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 2
样例输出
1