jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]

#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC085 A-  Already 2018
int main(void) {
	char s[11];
	
	
	scanf("%s",s);
//	s[3] = '8';
	printf("%.3s8%s\n",s,&s[4]);

	return 0;
}
//  [c]
#include <stdio.h>

int main(void)
{
        char s[10];
        scanf("%s",s);
        s[3]='8';
        printf("%s\n",s);
        return 0;
}
//  [javascript]
function test(input) {
  arr = input.split('');
  if (arr[3] = '7') {
    arr.splice(3, 1);
    arr.splice(3, 0, '8');
  }
  var str = arr.join('');
  console.log(str);
}
test(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var s = input[0].replace(/^2017/g, '2018');
    console.log(s);

    return 0;
}
//  [javascript]
const main = args => { console.log(args.replace(/2017/g, '2018')) };
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	fmt.Println("2018" + s[4:])
}
//  [go]
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)

	fmt.Println(strings.Replace(a, "2017", "2018", 1))

}
//  [ruby]
S=gets.chomp
S[3]='8'
puts S
//  [ruby]
s = gets.chomp
puts s.gsub("2017","2018")
//  [ruby]
puts gets.sub("2017","2018")
//  [rust]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		mut s: String,
	}

	s.remove(0);
	s.remove(0);
	s.remove(0);
	s.remove(0);
	println!("2018{}", s );
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    iterator.next().unwrap().replace("2017", "2018")
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        mut s: Chars,
    }

    s[3] = '8';
    for i in s {
        print!("{}",i);
    }

    print!("\n");

}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const S = input[0][0];

  return S.replace("2017", "2018");
};

console.log(main(read()));
//  [typescript]
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function slove() {
    const sc = new Scanner();
    const S = await sc.getLine();
    console.log(S.replace('2017/', '2018/'));
    sc.close();
  }

  slove();
}
//  [python]
n,m = map(int, input().split())
a = list(map(int, input().split()))

import numpy as np
a = np.array(a)
s = a.sum()
if s > n:
  print('-1')
else:
  print(n-s)
//  [python]
import sys
sys.setrecursionlimit(10000000)


def main():
    N, M = map(int, input().split())
    A = [int(c) for c in input().split()]
    import numpy as np
    sum_ = np.sum(A)
    if N - sum_ < 0:
        print(-1)
    else:
        print(N - sum_)


if __name__ == '__main__':
    main()
//  [python]
N, M = map(int,input().split())
A=list(map(int, input().split()))
for i in A:
    if sum(A) > N:
        ans = -1
    else:
        ans = N - sum(A)
print(ans)
//  [java]
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for(int i = 0; i < b; i++) {
			a -= sc.nextInt();
		}
		if(a<0) System.out.println(-1);
		else System.out.println(a);
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        int M = scan.nextInt();
        long[] A = new long[M];
        for (int i = 0; i < M; i++) {
            A[i] = scan.nextLong();
        }
        long sum = Arrays.stream(A).sum();
        if (N < sum) {
            System.out.println(-1);
        } else {
            System.out.println(N-sum);
        }
    }
}
//  [java]
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int holiday = scanner.nextInt();
		
		int homework = scanner.nextInt();
		
		List<Integer> list = new ArrayList<>();
		
		for (int i = 0; i < homework; i++) {
			
			list.add(scanner.nextInt());
		}
		
		scanner.close();
		
		int result = holiday - list.stream().mapToInt(x -> x).sum();
		
		if (result < 0) {
			System.out.println(-1);
		} else {
			System.out.println(result);
		}
		
	}

}
//  [cpp]

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll t=1;
ll n,x,m;
string s;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>m;
	vll a(m);
	for(ll i=0;i<m;i++) cin>>a[i];

	cout<<max((ll)-1,n - accumulate(all(a),0)) ;
}

int main() {
	fastio;randomINT;
	//cin>>t;
	while(t--) {
		MAIN();
	}
	return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main(void)
{
	int n, m,i,j,tmp, sum=0;
	scanf("%d %d", &n, &m);
	
	int A[10000];
	lop(i, m){
		scanf("%d", &A[i]);
	}
	
	for (i=0; i<m; ++i) {
    for (j=i+1; j<m; ++j) {
      if (A[i] <A[j]) {
        tmp =  A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }
 
	lop(i, m){
		sum+=A[i];
	}
	
	if(sum>n)printf("-1");
	else if(sum==n){ printf("0"); }
	else{ printf("%d", n-sum); }
	
	return 0;
}
//  [c]
#include<stdio.h>

int main(){
  int N,M;
  scanf("%d %d\n",&N,&M);
  int A[10000];
  int i;
  for(i = 0 ; i < 10000 ; i++){
    scanf("%d",&A[i]);
  }
  
  int sum;
  for(i = 0 ; i < M ; i++){
    sum = sum + A[i];
  }
  if(N-sum >= 0){
    printf("%d\n",N - sum);
  }else{
    printf("-1\n");
  }
  return 0;
}
//  [c]
#include<stdio.h>
#include<math.h>
int main(void) {
	int A,N,M,R;
	int i;
	int ans = 0;
	scanf("%d%d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d", &A);
		ans = ans + A;
	}
	if (N >= ans)
		printf("%d", N - ans);
	else
		printf("-1");
	return 0;
}
//  [javascript]
function Main(inputs) {
　　const inputlines = inputs.split("\n");
　　const limit = inputlines[0].split(" ").map(x => parseInt(x,10));
　　const inputvalues = inputlines[1].split(" ").map(x => parseInt(x,10));
	
　　var sum  = function(arr) {
　　　var sum = 0;
　　　arr.forEach(function(elm) {
　　　　　sum += elm;
　　　});
　　　return sum;
　　};
  
　　let total = limit[0] - sum(inputvalues);
  
　　console.log(total>=0?total:-1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const processData = (lines) => {
  const [N, M] = lines[0].split(' ').map(x => +x)
  const take = lines[1].split(' ').map(x => +x).reduce((r,x ) => r+x, 0)
  if (take > N) {
    console.log(-1)
  } else {
    console.log(N-take)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})
//  [javascript]
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
let lines = [];
reader.on("line", line => {
  lines.push(line);
});
reader.on("close", () => {
  const linesNum1 = lines[0].split(' ');
  const linesNum2 = lines[1].split(' ');
  const summerTime1 = linesNum1.map(str =>{ return Number(str) });
  const summerTime2 = linesNum2.map(str =>{ return Number(str) });
  let homeWork = summerTime2.reduce((a,x) => a += x);
  if(summerTime1[0] >= homeWork){
    console.log(summerTime1[0] - homeWork)
  } else {
    console.log('-1')
  }
});
//  [go]
package main

import "fmt"

func main() {
	var N, M, sum int
	fmt.Scan(&N, &M)
	A := make([]int, N)
	for i:= range A {
		fmt.Scan(&A[i])
		sum += A[i]
	}

	if N >= sum {
		fmt.Print(N-sum)
	} else{
		fmt.Print(-1)
	}


}
//  [go]
package main 

import (
  "fmt"
)

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  
  a := make([]int ,n)
  for i := 0; i < n; i++ {
  fmt.Scan(&a[i])
  }

  days := 0
  for _, x := range a {
    days += x
  }
  
  if n - days >= 0 {
  fmt.Println(n - days)
  } else {
  fmt.Println(-1)
  }
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sum := 0
	for i := 0; i < m; i++ {
		var a int
		fmt.Scan(&a)
		sum = sum + a
	}

	if sum <= n {
		fmt.Println(n - sum)
	} else {
		fmt.Println("-1")
	}
}
//  [ruby]
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

ans = n - a.sum
if ans >= 0
  puts ans
else
  puts -1
end
//  [ruby]
#!/usr/bin/env ruby

require 'pp'
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

N = attrs[0][0].to_i
A = attrs[1].map{|a| a.to_i}

n = N - A.inject(:+)
puts n<0 ? -1 : n
//  [ruby]
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M = gets_i_list
a_list = gets_i_list

hw_total = a_list.sum

if N >= hw_total
  puts N - hw_total
else
  puts -1
end
//  [swift]
import Foundation

let  homeworks = (readLine()!).components(separatedBy: " ").map{Int($0) ?? 0 }
var	 days = Array(repeating: 0, count: homeworks[1])
days = (readLine()!).components(separatedBy: " ").map{Int($0) ?? 0 }
let sum_days = days.reduce(0) {(num1: Int, num2: Int) -> Int in
    return num1 + num2
}

print( homeworks[0] >= sum_days ?   homeworks[0]-sum_days:-1)
//  [swift]
// Homework

func main() {
    let nm = readLine()!.split(separator: " ").map{Int($0)!}
    let a = readLine()!.split(separator: " ").map{Int($0)!}

    let workingdays = a.reduce(0, +)
    let rest = nm[0] - workingdays
    if rest < 0 {
        print(-1)
    } else { 
        print(rest)
    }
}

main()
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N] = input[0].map(Number);
  const A = input[1].map(Number);

  const remainingDays = N - A.reduce((acc, cur) => acc + cur);

  return remainingDays < 0 ? -1 : remainingDays;
};

console.log(main(read()));
//  [typescript]
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const vacation = Number(inputs[0].split(' ')[0]);
  const homeworkNum = Number(inputs[0].split(' ')[1]);
  const homework = inputs[1].split(' ').map(Number);

  const sum = homework.reduce((prev, current) => prev + current);

  if (vacation < sum) {
    console.log('-1');
  } else {
    console.log(vacation - sum);
  }
}
//  [python]
N,K = list(map(int,input().split()))     
ans = (N - 1)// (K - 1)                  
if (N-1) % (K -1) == 0:                  
    print(ans)                           
else:                                    
    print(ans + 1)
//  [python]
import math
s=input().split()
n,k=int(s[0])-1,int(s[1])-1
print(math.ceil(n/k))
//  [python]
N, K = map(int,input().split())
print((N-2)//(K-1)+1)
//  [python]
import numpy as np

def solve(N, K, As):
    return int(np.ceil((N-1) / (K-1)))

N, K = map(int, input().split())
As = map(int, input().split())
print(solve(N, K, As))
//  [python]
import numpy as np
import math

N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

A_np = np.array(A)

argmin = A_np.argmin() + 1

left = (math.ceil((argmin - K) / (K - 1)) + 1)
left = max(0, left)

already = (left - 1) * (K - 1) + K if left != 0 else 1

nokori = (N - already + 1)

right = (math.ceil((nokori - K) / (K - 1)) + 1)

print(right + left)
//  [python]
from math import ceil
import numpy as np

N, K = [int(c) for c in input().split()]
A = np.array([int(c) for c in input().split()])

min_num = 10000000
min_idx = np.argmin(A)
for i in range(K):
    # print(min_num)
    if ((min_idx - K + i + 1< 0) | (min_idx + i> N - 1)):
        continue
    else:
        min_num = min(min_num, 1 + ceil((min_idx - K + 1 + i)/(K - 1)) + ceil((N - min_idx - i - 1)/(K - 1)))
print(min_num)
//  [java]
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int cnt = 0;
		int same = 1;
		while (same < n) {
			same += k - 1;
			cnt++;
		}
		out.println(cnt);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String[] sl = s.split("[\\s]+");
    int n = Integer.parseInt(sl[0]);
    int k = Integer.parseInt(sl[1]);

    int v = 0;

    int a[] = new int[100001];
    s = r.readLine();
    sl = s.split("[\\s]+");

    for(int i = 1; i < n; i++)
    {
      a[i] = Integer.parseInt(sl[i - 1]);
      if(a[i] == 1)
      {
        v = i;
      }
    }

    int c = (v - 1 + k - 2) / (k - 1);

    int z = c * (k - 1) + 1;

    if(z < n) c += (n - z + k - 2) / (k - 1);

    System.out.println(c);
  }

}
//  [java]
import java.util.*;

public class Main {
    static int n, k;
    static int[] a;
    static int modP = 1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        a = new int[n];
        for(int i = 0; i < n; i++) a[i] = in.nextInt();

        int ans = (int)Math.ceil((double)(n - 1) / (double)(k - 1));

        System.out.println(ans);
    }
}
//  [java]
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int result = (int) Math.ceil((double) (n - k) / (k - 1)) + 1;

        // 出力
        System.out.println(result);
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, k;
	cin >> n >> k;
	cout << ceil((n - 1) * 1. / (k - 1));
	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, K;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;

    int ans = (N - 1 + K - 2) / (K - 1);
    cout << ans << endl;
}
//  [cpp]
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n,k;
    in(n,k);
    vector<int> vec(n);
    int minv,mini;
    rep(i,n){
        in(vec[i]);
        if(vec[i]==1){
            minv=vec[i];
            mini=i;
        }
    }
    int l,r,ans=10000000,kaisuu;
    for(int i=0;i<k;i++){
        l=mini-i;
        r=mini+k-1-i;
        debug(l,r);
        kaisuu=1;
        if(l>0){
            kaisuu+=l/(k-1);
            if(l%(k-1)!=0)kaisuu++;
        }
        if(r<n){
            kaisuu+=(n-1-r)/(k-1);
            if((n-1-r)%(k-1)!=0)kaisuu++;
        }
        ans=min(ans,kaisuu);
    }
    out(ans);
}
//  [cpp]
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

int main() {
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    for (size_t i = 0; i < N; i++) {
        cin >> A[i];
    }

    int ans = 1;
    int cnt = K;
    while (cnt < N) {
        cnt += K - 1;
        ++ans;
    }

    cout << ans << endl;

    return 0;
}
//  [cpp]
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int solve(int N, int K) {
    if(N == 1) return 0;

    int ub = INF, lb = -1;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        // mid 回で塗る

        int W = N + (mid - 1);
        if((W + K - 1) / K <= mid) {
            ub = mid;
        }
        else {
            lb = mid;
        }
    }
    return ub;
}
 
signed main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);

    int idx = -1;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        if(A[i] == 1) idx = i;
    }

    int ans = INF;
    for(int i=max(0LL, idx-K+1); i<=idx; i++) {
        int rl = i, rr = max(0LL, N - (i + K));

        // printf("i = %lld, rl = %lld, rr = %lld\n", i, rl, rr);

        int pl = solve(rl + 1, K);
        int pr = solve(rr + 1, K);
        chmin(ans, pl + pr + 1);
    }
    cout << ans << endl;
    return 0;
}
//  [c]

#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


int main(void)
{
	int  n, k,i,r,l;
	//char a[100001];

	i_cin2(n,k);

	//s_cin(a);

	r = 1;n -= k;
	k--;
    
	r += (n % k) ? n / k + 1 : n / k;
	i_cout(r);

	/*for (i = 0; i < n; i++)
		if (a[i] == '1') break;
	r = (i%(k-1))?i/k:i/k+1;

	n -= (i - 1);
	l = (n%(k-1))? n / k : n / k + 1;
	i_cout(n + l);*/

	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
	int N=0,K=0,count=0;

	scanf("%d %d",&N,&K);

	

	if((N-1)%(K-1)==0){
		count = (N-1)/(K-1);
	}
	
	else{
		count = (N-1)/(K-1)+1;
	}


	
		printf("%d",count);

	return 0;
}
//  [c]
#include<stdio.h>

int main(){
  int i = 0;
  int n = 0;
  int k = 0;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    if(n <= k + (k-1)*i){
      break;
    }
  }
  
  printf("%d",i+1);
  return 0;
}
//  [c]
#include<stdio.h>

int main(){
  int N,K,ans=0,j=1,a;
  scanf("%d%d",&N,&K);

  for (int i = 0; i < N; i++)
  {
    scanf("%d",&a);
  }
  

  while (j<N)
  {
    j+=K-1;
    ans++;
  }

  printf("%d",ans);

  return 0;
}
//  [c]
#include <stdio.h>
int main(void){
  int n,k,count=0, a[100005];

  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  n=n-k;
  count++;
  if(n>0){
    while(1){
    n=n-k+1;
    count++;
    if(n<=0) break;
  }
  }
  printf("%d",count);
  return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int n,k,a[100000];

    int i,j;

    scanf("%d %d",&n,&k);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }

    qsort(a,n,sizeof(int),asc);

    int ans = 0;
    for (i = 1; i < n; i++)
    {
        if(a[i - 1] != a[i])break;
    }
    
    printf("%d",(n - i + k - 2) / (k - 1));
}
//  [javascript]
function Main(input) {
    input = input.split("\n");
    tmp = input[0].split(" ");
    var n = parseInt(tmp[0], 10);
    var m = parseInt(tmp[1], 10);
    var res=Math.ceil((n-1)/(m-1));
    console.log('%d', res);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'
function Main(input) {
  input = input.split("\n")
  let line1 = input[0].split(' ')
  let N = parseInt(line1[0])
  let K = parseInt(line1[1])
  let A = input[1].split(' ')
  let ret = 0
  let minPos = -1
  for (let i = 0; i < N; i += 1) {
    if (minPos === -1 || A[minPos] > A[i]) minPos = i
  }
  console.log(Math.floor((N - 1 + K - 2) / (K - 1)))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))
//  [javascript]
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8"))},function(e,t){function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var i,l=e[Symbol.iterator]();!(n=(i=l.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==l.return||l.return()}finally{if(o)throw u}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){var t=e.split("\n"),n=r(t[0].split(" ").map(function(e){return Number(e)}),2),o=n[0],u=n[1],i=(t[1].split(" ").map(function(e){return Number(e)}),1+Math.ceil((o-u)/(u-1)));console.log(i)}},function(e,t){e.exports=require("fs")}]);
//  [javascript]
function Main(s){
  s = s.split("\n");
  var n = s[0].split(" ").map(a=>+a);
  var k = n[1];
  n = n[0];
  var a = s[1].split(" ").map(a=>+a);
  var x = a.findIndex(a=>a===1);
  console.log(Math.ceil((n-1)/(k-1)));
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));
//  [javascript]
function Main(arg) {
  var n = arg.split("\n")[0].split(" ")[0] - 0;
  var k = arg.split("\n")[0].split(" ")[1] - 0;

  console.log(Math.ceil((n - 1) / (k - 1)));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
    input = input.split("\n");
    var [p,k] = input[0].split(" ");
    var arr = input[1].split(" ");
    var n = arr.length;
    console.log(Math.ceil((n-1)/(k-1)));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	K, _ := strconv.Atoi(sc.Text())
	ans := (N - 1) / (K - 1)
	if (N-1)%(K-1) > 0 {
		ans++
	}
	fmt.Printf(`%d`, ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n, k := getInt(), getInt()
	n -= k
	k--

	ans := 1 + (n+k-1)/k
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	ans := ((n - 1) + (k - 2)) / (k - 1)
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	//ans := (float64(n) - 1.0) / (float64(k) - 1.0)
	fmt.Println(kiriage(n-1, k-1))

}
func kiriage(a int, b int) int {
	return (a + b - 1) / b // a/bを切り上げ
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [ruby]
n,k = gets.split.map(&:to_i)
gets

puts (n - 1).fdiv(k - 1).ceil
//  [ruby]
eval"p~-~-%d/~-%d+1"%gets.split
//  [ruby]
n,m=gets.split;p~-~-n.to_i/~-m.to_i+1
//  [ruby]
N,K,*A=`dd`.split.map &:to_i
i=A.index(1)
puts (i-K+1..i).map{|j|
    L=[(j+(K-1)-1)/(K-1), 0].max
    R=[(N-(j+K)+(K-1)-1)/(K-1), 0].max
    L+R+1
}.min
//  [ruby]
n,k=gets.split.map(&:to_f)
a=gets.split.map(&:to_i)
pl=a.index(1)
list=[]
k.to_i.times{|i|
  list<<[((pl+i-k+1)/(k-1)).ceil,0].max+[((n-(i+1)-pl)/(k-1)).ceil,0].max
  }
#list=[[((pl-2)/(k-1)).ceil,0].max+[((n-1-pl)/(k-1)).ceil,0].max,[((pl-1)/(k-1)).ceil,0].max+[((n-2-pl)/(k-1)).ceil,0].max,[(pl/(k-1)).ceil,0].max+[((n-3-pl)/(k-1)).ceil,0].max]
p list.min+1
//  [ruby]
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end


N,K=gets.chomp.split(' ').map{|n| n.to_i}
S=gets.chomp.split(' ').map{|n| n.to_i}
if(N<K)
	puts 1
	exit(0)
end
min = 9999999999
mini = 0
S.each_with_index{|a,i|
	a < min ? (min = a; mini = i) : a
}
num = 1
mintmpnum = 9999999999
0.upto(K-1){|offset|
	tmpnum = 0
	lefti = mini-0-(K-1)+offset-1
	if(0<=lefti)
		tmpnum += ((lefti+1)*1.0 / (K-1)).ceil
		dputs "lefti"; dputs lefti
		dputs "tmpnum"; dputs tmpnum
	end
	righti = mini+(K-1)-(K-1-offset)+1
	if(righti<=N-1)
		tmpnum += ((N-1-righti+1)*1.0 / (K-1)).ceil
		dputs "righti" ; dputs righti
		dputs "tmpnum"; dputs tmpnum
	end
	tmpnum < mintmpnum ? mintmpnum = tmpnum : mintmpnum
}
puts num+mintmpnum
//  [rust]
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    println!("{}", (n + k - 3) / (k - 1));
}
//  [rust]
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn ceil(x: usize, y:usize) -> usize {
    (x + y - 1) / y
}


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    println!("{}", ceil(n - 1, k - 1));
}
//  [rust]
#[allow(dead_code)]
fn main() {
    let (n, k) = i::u2();
    let a = i::uv(n);
    println!("{}", 1 + (n - 2) / (k - 1));
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}
//  [rust]
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let mut aseq = vec![0; n];
    let mut zero_pos = 0;
    for i in 0..n {
        aseq[i] = read::<usize>() - 1;
        if aseq[i] == 0 {
            zero_pos = i;
        }
    }
    let left_cnt = (zero_pos + k - 2) / (k - 1);
    let left_rest = left_cnt * (k - 1) - zero_pos;
    let right_cnt = if left_rest > n - zero_pos - 1 {
        0
    } else {
        (n - zero_pos - 1 - left_rest + k - 2) / (k - 1)
    };
    let ans = left_cnt + right_cnt;
    println!("{}", ans);
}
//  [swift]
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, K) = (input[0], input[1])
let _ = readLine()
print((N-2)/(K-1)+1)
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!-1};print((i[0]-1)/i[1]+1)
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!};print((i[0]-2)/(i[1]-1)+1)
//  [swift]
let i=readLine()!.characters.split(" ").map{Int(String($0))!},_=readLine();print((i[0]-2)/(i[1]-1)+1)
//  [typescript]
"use strict"
let fs = require('fs');
let input = fs.readFileSync("/dev/stdin", "utf8").split(/\s/);
const N = +input[0];
const K = +input[1];
let ans = 1;
if(N > K) {
  for(let i= N - K; i > 0; i -= K - 1) ans++;
}
console.log(ans);
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, k] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

let a = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const res = _ => {
  const d = k - 1
  const l = n - 1
  return Math.ceil(l / d)
}

console.log(res())
//  [python]

def solve(A,op):
    result=[0]*4
    result[0]=A[0]
    for i in range(2):
        if i==0:
            result[1]=result[0]+A[1]
            op[0]="+"
        else:
            result[1]=result[0]-A[1]
            op[0]="-"
        for j in range(2):
            if j==0:
                result[2] = result[1]+A[2]
                op[1]="+"
            else:
                result[2] = result[1]-A[2]
                op[1]="-"
            for k in range(2):
                if k==0:
                    result[3] = result[2]+A[3]
                    op[2]="+"
                else:
                    result[3] = result[2]-A[3]
                    op[2]="-"
                #print("{}{}{}{}{}{}{}?7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                #print(result[3])
                if result[3]==7:
                    print("{}{}{}{}{}{}{}=7".format(A[0],op[0],A[1],op[1],A[2],op[2],A[3]))
                    return

def main():
    A=[0]*4
    op=[""]*3
    A=list(map(int,input()))
    solve(A,op)

if __name__=="__main__":
    main()
//  [python]
list_s = list(str(input()))
for i in range(4):
    list_s[i] = int(list_s[i])

for i in range(2):
    for j in range(2):
        for k in range(2):
            ans = 0
            if i == 0:
                ans += list_s[0] + list_s[1]
            else:
                ans += list_s[0] - list_s[1]
            if j == 0:
                ans += list_s[2]
            else:
                ans -= list_s[2]
            if k == 0:
                ans += list_s[3]
            else:
                ans -= list_s[3]
            if ans == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
list_sgn = ["+","-"]
print(str(list_s[0]) + list_sgn[i] + str(list_s[1]) + list_sgn[j] + str(list_s[2]) + list_sgn[k] + str(list_s[3]) + "=7")
//  [python]
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    
    else:
        dfs(i+1, f + "-" + s[i+1], sum - int(s[i+1]))
        dfs(i+1, f + "+" + s[i+1], sum + int(s[i+1]))


s = input()
dfs(0,s[0], int(s[0]))