Problem:
Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)








import java.util.*;
import java.util.Map.Entry;



public class Main{
	
	public int num;
	public int vol;

	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt(),K=sc.nextInt();
	 int[] A=new int[N];
	 int min=Integer.MAX_VALUE;
	 int minindex=0;
			 
	 int result = 0;
	 for(int i=0;i<N;i++) {
		 A[i]=sc.nextInt();
		 if(min>A[i]) {
			 min=A[i];
			 minindex=i;
		 }
	 }
	 
	 int currentindex = minindex;
	 
	 while(true) {
		 
		 
		 int i=0;
		 boolean modifyed = false;
		 for(i=currentindex;i<currentindex+K;i++) {
			 if(A[i]!=min) {
				 modifyed = true;
				 A[i] = min;
			 }
			 
			 if(i==N-1) {
				
				 currentindex=N-1;
				 break;
			 }
			 
		 }
		 
			 
		 /*
		 for(int j=0;j<N;j++) {
			 System.out.print(" "+A[j]);
		 }*/
		 
		 if(modifyed) {
			 result++;
		 }
		 
		 if(currentindex!=N-1) {
			 currentindex=i-1;
		 }else {
			 break;
		 }
		 
		 //System.out.println("\n"+currentindex);
		 
		 //System.out.println();
	 }
	 //System.out.println();
	 currentindex = minindex;
	 
 while(true) {
		 
		 
		 int i=0;
		 boolean modifyed = false;
		 for(i=currentindex;i>currentindex-K;i--) {
			 
			 if(A[i]!=min) {
				 modifyed = true;
				 A[i] = min;
			 }
			 if(i==0) {
				
				 currentindex=0;
				 break;
			 }
			 
		 }
		 
			 /*
		 for(int j=0;j<N;j++) {
			 System.out.print(" "+A[j]);
		 }*/
		 
		 if(modifyed) {
			 result++;
		 }
		 
		 if(currentindex!=0) {
			 currentindex=i+1;
		 }else {
			 break;
		 }
		 
		 //System.out.println("\n"+currentindex);
		 
		// System.out.println();
	 }
	 
	 
	 
	 
	 
	 System.out.println(result);
	 
 }
	


}