Problem:
Score : 100 points

Problem Statement

There is an N-car train.

You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."

Constraints

1 \leq N \leq 100

1 \leq i \leq N

Input

Input is given from Standard Input in the following format:

N i

Output

Print the answer.

Sample Input 1

4 2

Sample Output 1

3

The second car from the front of a 4-car train is the third car from the back.

Sample Input 2

1 1

Sample Output 2

1

Sample Input 3

15 11

Sample Output 3

5

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main tr = new Main();
		tr.test(sc);
		sc.close();
	}
	
	void test(Scanner sc){
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] a = new int[N+1];
		a[1] = sc.nextInt();
		int here=-1;
		for (int i = 2; i <= N; i++) {
			a[i] = sc.nextInt();
			if(a[i-1]<= 0 && a[i] > 0){
				here = i;
			}
		}
		int out=0;
		if(here==-1){
			// all in one side
			if(a[1]>=0){
				out += a[K]; 
			}else{
				out += (-1 * a[N+1-K]);
			}
		}else{
			out  = Integer.MAX_VALUE;
			here--;
			int left = here>K?here-1-K:1;
			int right = left + K -1;
			here++;
			while(left<=here && right <= N){
				int dist = a[right]-a[left];
				int addme=0;
				if(a[left]<0){
					addme = (-1 * a[left]);
				}else{
					addme =a[left];
				}
				
				addme = addme>a[N]?a[N]:addme;
				
				dist+=addme;
				if(out>dist){
					out=dist;
				}
				left++;
				right++;
			}
		}
		System.out.println(out);
	}
}