program AGC025A
    implicit none
    integer(8)::N,A,B,i,ans,dig
    read*,N
    ans=9999999

    do i=1,N-1
        A=i
        B=N-i
        dig=0
        do
            dig=dig+mod(A,10)
            A=A/10
            if(A==0)exit
        end do

        do
            dig=dig+mod(B,10)
            B=B/10
            if(B==0)exit
        end do
        ans=min(ans,dig)
    end do

    print'(i0)',ans
end program AGC025A
; 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"

@_QQcl.47afed85ca7745c385322dda50de2a8a = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5919/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.47afed85ca7745c385322dda50de2a8a, i32 4)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %.02022 = add i64 %5, -1
  %6 = icmp sgt i64 %.02022, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %17
  %.024 = phi i64 [ %19, %17 ], [ 1, %0 ]
  %.01823 = phi i64 [ %18, %17 ], [ 9999999, %0 ]
  br label %7

7:                                                ; preds = %7, %.lr.ph
  %.019 = phi i64 [ %.024, %.lr.ph ], [ %10, %7 ]
  %.016 = phi i64 [ 0, %.lr.ph ], [ %9, %7 ]
  %8 = srem i64 %.019, 10
  %9 = add i64 %.016, %8
  %10 = sdiv i64 %.019, 10
  %.019.off = add i64 %.019, 9
  %11 = icmp ult i64 %.019.off, 19
  br i1 %11, label %.preheader.preheader, label %7

.preheader.preheader:                             ; preds = %7
  %12 = sub i64 %5, %.024
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.017 = phi i64 [ %15, %.preheader ], [ %12, %.preheader.preheader ]
  %.1 = phi i64 [ %14, %.preheader ], [ %9, %.preheader.preheader ]
  %13 = srem i64 %.017, 10
  %14 = add i64 %.1, %13
  %15 = sdiv i64 %.017, 10
  %.017.off = add i64 %.017, 9
  %16 = icmp ult i64 %.017.off, 19
  br i1 %16, label %17, label %.preheader

17:                                               ; preds = %.preheader
  %18 = call i64 @llvm.smin.i64(i64 %.01823, i64 %14)
  %19 = add nuw i64 %.024, 1
  %exitcond.not = icmp eq i64 %19, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %17, %0
  %.018.lcssa = phi i64 [ 9999999, %0 ], [ %18, %17 ]
  %20 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.47afed85ca7745c385322dda50de2a8a, i32 25)
  %21 = call i1 @_FortranAioOutputInteger64(ptr %20, i64 %.018.lcssa)
  %22 = call i32 @_FortranAioEndIoStatement(ptr %20)
  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 ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #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"}
