program main
  implicit none
  integer :: n, i, k, hap
  character(100000) :: s
  read (*, *) n, k
  read (*, *) s
  hap = 0
  do i = 1, n
    if (i == 1) then
      if (s(1:1) == "R" .and. s(2:2) == "R") hap = hap + 1
    else if (i == n) then
      if (s(n:n) == "L" .and. s(n - 1:n - 1) == "L") hap = hap + 1
    else
      if (s(i:i) == "L") then
        if (s(i - 1:i - 1) == "L") hap = hap + 1
      else
        if (s(i + 1:i + 1) == "R") hap = hap + 1
      end if
    end if
  end do
  write (*, "(i0)") min(n - 1, hap + 2 * k)
end program main

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
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"

@_QFEs = internal global [100000 x i8] undef
@_QQcl.79b9393588b105452365d535d5bfb094 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3321/source.f\00"
@_QQcl.52 = linkonce constant [1 x i8] c"R"
@_QQcl.4C = linkonce constant [1 x i8] c"L"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.79b9393588b105452365d535d5bfb094, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.79b9393588b105452365d535d5bfb094, i32 6)
  %8 = call i1 @_FortranAioInputAscii(ptr %7, ptr nonnull @_QFEs, i64 100000)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %7)
  %10 = load i32, ptr %2, align 4, !tbaa !3
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %._crit_edge

12:                                               ; preds = %0
  %13 = zext i32 %10 to i64
  %14 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull @_QFEs, ptr nonnull @_QQcl.52, i64 1, i64 1)
  %15 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull getelementptr inbounds ([100000 x i8], ptr @_QFEs, i64 0, i64 1), ptr nonnull @_QQcl.52, i64 1, i64 1)
  %16 = or i32 %15, %14
  %.pn.in.peel = icmp eq i32 %16, 0
  %.pn.peel = zext i1 %.pn.in.peel to i32
  %exitcond.peel.not = icmp eq i32 %10, 1
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %12, %47
  %indvars.iv = phi i64 [ %indvars.iv.next, %47 ], [ 2, %12 ]
  %.017 = phi i32 [ %.1, %47 ], [ %.pn.peel, %12 ]
  %17 = load i32, ptr %2, align 4, !tbaa !3
  %18 = zext i32 %17 to i64
  %19 = icmp eq i64 %indvars.iv, %18
  br i1 %19, label %20, label %32

20:                                               ; preds = %.lr.ph.peel.next
  %21 = sext i32 %17 to i64
  %22 = add nsw i64 %21, -1
  %23 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %22
  %24 = call i32 @_FortranACharacterCompareScalar1(ptr %23, ptr nonnull @_QQcl.4C, i64 1, i64 1)
  %25 = load i32, ptr %2, align 4, !tbaa !3
  %26 = add i32 %25, -1
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %27, -1
  %29 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %28
  %30 = call i32 @_FortranACharacterCompareScalar1(ptr %29, ptr nonnull @_QQcl.4C, i64 1, i64 1)
  %31 = or i32 %30, %24
  br label %47

32:                                               ; preds = %.lr.ph.peel.next
  %33 = add nsw i64 %indvars.iv, -1
  %34 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %33
  %35 = call i32 @_FortranACharacterCompareScalar1(ptr %34, ptr nonnull @_QQcl.4C, i64 1, i64 1)
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %32
  %38 = add nsw i64 %indvars.iv, -2
  %39 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %38
  %40 = call i32 @_FortranACharacterCompareScalar1(ptr %39, ptr nonnull @_QQcl.4C, i64 1, i64 1)
  br label %47

41:                                               ; preds = %32
  %42 = shl i64 %indvars.iv, 32
  %sext = add i64 %42, 4294967296
  %43 = ashr exact i64 %sext, 32
  %44 = add nsw i64 %43, -1
  %45 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %44
  %46 = call i32 @_FortranACharacterCompareScalar1(ptr %45, ptr nonnull @_QQcl.52, i64 1, i64 1)
  br label %47

47:                                               ; preds = %41, %37, %20
  %.pn.in.in = phi i32 [ %31, %20 ], [ %40, %37 ], [ %46, %41 ]
  %.pn.in = icmp eq i32 %.pn.in.in, 0
  %.pn = zext i1 %.pn.in to i32
  %.1 = add i32 %.017, %.pn
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.peel.next, !llvm.loop !7

._crit_edge:                                      ; preds = %47, %12, %0
  %.0.lcssa = phi i32 [ 0, %0 ], [ %.pn.peel, %12 ], [ %.1, %47 ]
  %48 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.79b9393588b105452365d535d5bfb094, i32 21)
  %49 = load i32, ptr %2, align 4, !tbaa !3
  %50 = add i32 %49, -1
  %51 = load i32, ptr %1, align 4, !tbaa !3
  %52 = shl i32 %51, 1
  %53 = add i32 %52, %.0.lcssa
  %54 = call i32 @llvm.smin.i32(i32 %50, i32 %53)
  %55 = call i1 @_FortranAioOutputInteger32(ptr %48, i32 %54)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %48)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare i32 @_FortranACharacterCompareScalar1(ptr, ptr, i64, i64) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.peeled.count", i32 1}
