#import <stdio.h>
#import <stdlib.h>
#import <limits.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

long CEIL(double x) {
    long i = (long)x;
    return i + (((x != i) && (x > 0)) ? 1 : 0);
}

int main(int argc, const char * argv[]) {
    long N, K;
    scanf("%ld %ld", &N, &K);
    
    long n;
    long i = 0;
    while (scanf("%ld", &n) != EOF) {
        if (n==1) {
            break;
        }
        i++;
    }
    
    long JMIN = MAX(0,-N+K+i);
    long JMAX = MIN(K-1,i);
    long min = LONG_MAX;
    for(long j=JMIN;j<=JMAX;j++){
        min = MIN(min, 1 + CEIL((double)(i-j)/(K-1)) + CEIL((double)(N-i-K+j)/(K-1)) );
    }
    
    printf("%ld", min);
    
    return 0;
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_504/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_504/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [8 x i8] c"%ld %ld\00", align 1
@.str.1 = private unnamed_addr constant [4 x i8] c"%ld\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @CEIL(double noundef %x) local_unnamed_addr #0 {
entry:
  %conv = fptosi double %x to i64
  %conv1 = sitofp i64 %conv to double
  %cmp = fcmp une double %conv1, %x
  %cmp3 = fcmp ogt double %x, 0.000000e+00
  %0 = and i1 %cmp3, %cmp
  %conv5 = zext i1 %0 to i64
  %add = add nsw i64 %conv5, %conv
  ret i64 %add
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main(i32 noundef %argc, ptr nocapture noundef readnone %argv) local_unnamed_addr #2 {
entry:
  %N = alloca i64, align 8
  %K = alloca i64, align 8
  %n = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %N) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %K) #5
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N, ptr noundef nonnull %K)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #5
  br label %while.cond

while.cond:                                       ; preds = %while.cond, %entry
  %i.0 = phi i64 [ 0, %entry ], [ %inc, %while.cond ]
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %n)
  %cmp = icmp eq i32 %call1, -1
  %0 = load i64, ptr %n, align 8
  %cmp2 = icmp eq i64 %0, 1
  %or.cond = select i1 %cmp, i1 true, i1 %cmp2
  %inc = add nuw nsw i64 %i.0, 1
  br i1 %or.cond, label %while.end, label %while.cond

while.end:                                        ; preds = %while.cond
  %1 = load i64, ptr %N, align 8, !tbaa !5
  %2 = load i64, ptr %K, align 8
  %add = sub i64 %i.0, %1
  %add3 = add i64 %add, %2
  %spec.select = call i64 @llvm.smax.i64(i64 %add3, i64 0)
  %sub8 = add nsw i64 %2, -1
  %cond14 = call i64 @llvm.smin.i64(i64 %sub8, i64 %i.0)
  %cmp15.not90 = icmp sgt i64 %spec.select, %cond14
  br i1 %cmp15.not90, label %for.cond.cleanup, label %for.body.lr.ph

for.body.lr.ph:                                   ; preds = %while.end
  %conv18 = sitofp i64 %sub8 to double
  %3 = add i64 %i.0, %2
  %sub22 = sub i64 %1, %3
  %4 = add i64 %cond14, 1
  %5 = sub i64 %4, %spec.select
  %min.iters.check = icmp ult i64 %5, 2
  br i1 %min.iters.check, label %for.body.preheader, label %vector.ph

vector.ph:                                        ; preds = %for.body.lr.ph
  %n.vec = and i64 %5, -2
  %ind.end = add i64 %spec.select, %n.vec
  %.splatinsert = insertelement <2 x i64> poison, i64 %spec.select, i64 0
  %.splat = shufflevector <2 x i64> %.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %induction = add nuw <2 x i64> %.splat, <i64 0, i64 1>
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %i.0, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert93 = insertelement <2 x double> poison, double %conv18, i64 0
  %broadcast.splat94 = shufflevector <2 x double> %broadcast.splatinsert93, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert95 = insertelement <2 x i64> poison, i64 %sub22, i64 0
  %broadcast.splat96 = shufflevector <2 x i64> %broadcast.splatinsert95, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ %induction, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ <i64 9223372036854775807, i64 9223372036854775807>, %vector.ph ], [ %28, %vector.body ]
  %6 = sub nsw <2 x i64> %broadcast.splat, %vec.ind
  %7 = sitofp <2 x i64> %6 to <2 x double>
  %8 = fdiv <2 x double> %7, %broadcast.splat94
  %9 = fptosi <2 x double> %8 to <2 x i64>
  %10 = sitofp <2 x i64> %9 to <2 x double>
  %11 = fcmp une <2 x double> %8, %10
  %12 = fcmp ogt <2 x double> %8, zeroinitializer
  %13 = and <2 x i1> %12, %11
  %14 = zext <2 x i1> %13 to <2 x i64>
  %15 = add nsw <2 x i64> %broadcast.splat96, %vec.ind
  %16 = sitofp <2 x i64> %15 to <2 x double>
  %17 = fdiv <2 x double> %16, %broadcast.splat94
  %18 = fptosi <2 x double> %17 to <2 x i64>
  %19 = sitofp <2 x i64> %18 to <2 x double>
  %20 = fcmp une <2 x double> %17, %19
  %21 = fcmp ogt <2 x double> %17, zeroinitializer
  %22 = and <2 x i1> %21, %20
  %23 = zext <2 x i1> %22 to <2 x i64>
  %24 = add <2 x i64> %18, <i64 1, i64 1>
  %25 = add <2 x i64> %24, %9
  %26 = add <2 x i64> %25, %23
  %27 = add <2 x i64> %26, %14
  %28 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %vec.phi, <2 x i64> %27)
  %index.next = add nuw i64 %index, 2
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %30 = call i64 @llvm.vector.reduce.smin.v2i64(<2 x i64> %28)
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %for.cond.cleanup, label %for.body.preheader

for.body.preheader:                               ; preds = %for.body.lr.ph, %middle.block
  %j.092.ph = phi i64 [ %spec.select, %for.body.lr.ph ], [ %ind.end, %middle.block ]
  %min.091.ph = phi i64 [ 9223372036854775807, %for.body.lr.ph ], [ %30, %middle.block ]
  br label %for.body

for.cond.cleanup:                                 ; preds = %for.body, %middle.block, %while.end
  %min.0.lcssa = phi i64 [ 9223372036854775807, %while.end ], [ %30, %middle.block ], [ %spec.select87, %for.body ]
  %call53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %min.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %K) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %N) #5
  ret i32 0

for.body:                                         ; preds = %for.body.preheader, %for.body
  %j.092 = phi i64 [ %inc52, %for.body ], [ %j.092.ph, %for.body.preheader ]
  %min.091 = phi i64 [ %spec.select87, %for.body ], [ %min.091.ph, %for.body.preheader ]
  %sub16 = sub nsw i64 %i.0, %j.092
  %conv = sitofp i64 %sub16 to double
  %div = fdiv double %conv, %conv18
  %conv.i = fptosi double %div to i64
  %conv1.i = sitofp i64 %conv.i to double
  %cmp.i = fcmp une double %div, %conv1.i
  %cmp3.i = fcmp ogt double %div, 0.000000e+00
  %31 = and i1 %cmp3.i, %cmp.i
  %conv5.i = zext i1 %31 to i64
  %add23 = add nsw i64 %sub22, %j.092
  %conv24 = sitofp i64 %add23 to double
  %div27 = fdiv double %conv24, %conv18
  %conv.i69 = fptosi double %div27 to i64
  %conv1.i70 = sitofp i64 %conv.i69 to double
  %cmp.i71 = fcmp une double %div27, %conv1.i70
  %cmp3.i72 = fcmp ogt double %div27, 0.000000e+00
  %32 = and i1 %cmp3.i72, %cmp.i71
  %conv5.i73 = zext i1 %32 to i64
  %add.i = add i64 %conv.i69, 1
  %add20 = add i64 %add.i, %conv.i
  %add.i74 = add i64 %add20, %conv5.i73
  %add29 = add i64 %add.i74, %conv5.i
  %spec.select87 = call i64 @llvm.smin.i64(i64 %min.091, i64 %add29)
  %inc52 = add nuw nsw i64 %j.092, 1
  %cmp15.not.not = icmp slt i64 %j.092, %cond14
  br i1 %cmp15.not.not, label %for.body, label %for.cond.cleanup, !llvm.loop !12
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.smin.v2i64(<2 x i64>, <2 x i64>) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.smin.v2i64(<2 x i64>) #4

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
