For this Question: There is circular river with circumference K. There are N cities on the banks of the river. The position p(i) of the i-th city is defined as its distance from the topmost point of the river in the clockwise manner.
You are given the positions of all the N cities, your task is to find the minimum distance you need to travel to visit all the N cities. You can start at whichever point you like, and can move both clockwise and anticlockwise around the river.

See sample for better understanding.

Topmost point here refers to one fixed point on the banks of the river.The first line of the input contains two number K and N.
The second line contains N singly spaced integers denoting the position of cities p(1), p(2),. , p(N).

Constraints
1 <= N <= 200000
1 <= K <= 1000000
0 <= p(1) < p(2) < p(3). . < p(N) < KOutput a single integer, the minimum distance you need to cover to visit all the N cities.Sample Input
20 3
0 5 15

Sample Output
10

Explanation: We start at 3rd city, then visit 1st city, then visit 2nd city. Total distance covered = 5 + 5 = 10.

Sample Input
20 3
5 10 15

Sample Output
10, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s[] = br.readLine().split(" ");
		int c = Integer.parseInt(s[0]);
		int n = Integer.parseInt(s[1]);

		int sum = 0;
		int pre = 0;
		int first = 0;
		int max = 0;
		int t = 0;
		int d = 0;

		s = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			t = Integer.parseInt(s[i]);

			if(i == 0){
			first = t;
			pre = t;
			continue;
			}

			if(i == n-1){
				d = c - t + first;
				sum += d;

				if(max < d)
				max = d;
			}

			d = t - pre;

			sum += d;

			if(max < d)
			max = d;



			pre = t;
		}
		System.out.println(sum-max);


	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?