implicit none
integer k
integer i,j,l
character :: s*5008,ans(5)*6
read*,s,k
ans = "zzzzz"
l = len_trim(s)
do i=1,l
  do j=0,4
    if( any(ans==s(i:i+j)) .or. l<i+j )cycle
    if(s(i:i+j)<ans(1))then
      ans(5) = ans(4)
      ans(4) = ans(3)
      ans(3) = ans(2)
      ans(2) = ans(1)
      ans(1) = s(i:i+j)
    else if(s(i:i+j)<ans(2))then
      ans(5) = ans(4)
      ans(4) = ans(3)
      ans(3) = ans(2)
      ans(2) = s(i:i+j)
    else if(s(i:i+j)<ans(3))then
      ans(5) = ans(4)
      ans(4) = ans(3)
      ans(3) = s(i:i+j)
    else if(s(i:i+j)<ans(4))then
      ans(5) = ans(4)
      ans(4) = s(i:i+j)
    else if(s(i:i+j)<ans(5))then
      ans(5) = s(i:i+j)
    endif
  enddo
enddo

print'(a)',ans(k)
end
; 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 [5008 x i8] undef
@_QQcl.550e93d0b9a3aa7eae4c5202b0ddf7fd = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5994/source.f\00"
@_QQcl.7A7A7A7A7A = linkonce local_unnamed_addr constant [5 x i8] c"zzzzz"
@_QQcl.286129 = linkonce constant [3 x i8] c"(a)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

define void @_QQmain() local_unnamed_addr {
.preheader48.preheader:
  %0 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %1 = alloca [5 x [6 x i8]], align 1
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.550e93d0b9a3aa7eae4c5202b0ddf7fd, i32 5)
  %4 = tail call i1 @_FortranAioInputAscii(ptr %3, ptr nonnull @_QFEs, i64 5008)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %1, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.7A7A7A7A7A, i64 5, i1 false)
  %7 = getelementptr inbounds [6 x [1 x i8]], ptr %1, i64 0, i64 5
  store i8 32, ptr %7, align 1, !tbaa !3
  %8 = getelementptr inbounds [6 x i8], ptr %1, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %8, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.7A7A7A7A7A, i64 5, i1 false)
  %9 = getelementptr inbounds [6 x i8], ptr %1, i64 1, i64 5
  store i8 32, ptr %9, align 1, !tbaa !3
  %10 = getelementptr inbounds [6 x i8], ptr %1, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %10, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.7A7A7A7A7A, i64 5, i1 false)
  %11 = getelementptr inbounds [6 x i8], ptr %1, i64 2, i64 5
  store i8 32, ptr %11, align 1, !tbaa !3
  %12 = getelementptr inbounds [6 x i8], ptr %1, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %12, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.7A7A7A7A7A, i64 5, i1 false)
  %13 = getelementptr inbounds [6 x i8], ptr %1, i64 3, i64 5
  store i8 32, ptr %13, align 1, !tbaa !3
  %14 = getelementptr inbounds [6 x i8], ptr %1, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %14, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.7A7A7A7A7A, i64 5, i1 false)
  %15 = getelementptr inbounds [6 x i8], ptr %1, i64 4, i64 5
  store i8 32, ptr %15, align 1, !tbaa !3
  br label %.preheader48

.preheader48:                                     ; preds = %.preheader48.preheader, %.preheader48
  %16 = phi i64 [ %20, %.preheader48 ], [ 5007, %.preheader48.preheader ]
  %17 = getelementptr [5008 x [1 x i8]], ptr @_QFEs, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !3
  %19 = icmp eq i8 %18, 32
  %20 = add nsw i64 %16, -1
  %21 = icmp ne i64 %16, 0
  %22 = and i1 %19, %21
  br i1 %22, label %.preheader48, label %23

23:                                               ; preds = %.preheader48
  %24 = trunc i64 %16 to i32
  %25 = add i32 %24, 1
  %26 = select i1 %19, i32 0, i32 %25
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %23
  %28 = zext i32 %26 to i64
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 1
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 2
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 3
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 4
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 5
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 6
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 0
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %90
  %indvars.iv76 = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next77, %90 ]
  %indvar = phi i64 [ 0, %.preheader.lr.ph ], [ %indvar.next, %90 ]
  %29 = xor i64 %indvar, -1
  %30 = add nsw i64 %indvars.iv76, -1
  %31 = getelementptr [5008 x [1 x i8]], ptr @_QFEs, i64 0, i64 %30
  br label %32

32:                                               ; preds = %.preheader, %.loopexit
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %.loopexit ]
  %33 = add nuw nsw i64 %indvars.iv76, %indvars.iv
  %34 = trunc i64 %33 to i32
  %sext = shl i64 %33, 32
  %35 = ashr exact i64 %sext, 32
  %36 = add i64 %35, %29
  %smax72 = call i64 @llvm.smax.i64(i64 %36, i64 -1)
  %37 = call i64 @llvm.smin.i64(i64 %smax72, i64 5)
  %smin73 = add nsw i64 %37, 1
  %uglygep74 = getelementptr i8, ptr %1, i64 %smin73
  %38 = sub nsw i64 5, %37
  %uglygep71 = getelementptr i8, ptr %8, i64 %smin73
  %uglygep67 = getelementptr i8, ptr %10, i64 %smin73
  %uglygep63 = getelementptr i8, ptr %12, i64 %smin73
  %uglygep59 = getelementptr i8, ptr %14, i64 %smin73
  %39 = sub nsw i64 %35, %indvars.iv76
  %40 = call i64 @llvm.smax.i64(i64 %39, i64 -1)
  %41 = add nsw i64 %40, 1
  %42 = call dereferenceable_or_null(20) ptr @malloc(i64 20)
  %43 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull %1, ptr %31, i64 6, i64 %41)
  %44 = icmp eq i32 %43, 0
  %45 = zext i1 %44 to i32
  store i32 %45, ptr %42, align 4, !tbaa !3
  %46 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull %8, ptr %31, i64 6, i64 %41)
  %47 = icmp eq i32 %46, 0
  %48 = zext i1 %47 to i32
  %49 = getelementptr i32, ptr %42, i64 1
  store i32 %48, ptr %49, align 4, !tbaa !3
  %50 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull %10, ptr %31, i64 6, i64 %41)
  %51 = icmp eq i32 %50, 0
  %52 = zext i1 %51 to i32
  %53 = getelementptr i32, ptr %42, i64 2
  store i32 %52, ptr %53, align 4, !tbaa !3
  %54 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull %12, ptr %31, i64 6, i64 %41)
  %55 = icmp eq i32 %54, 0
  %56 = zext i1 %55 to i32
  %57 = getelementptr i32, ptr %42, i64 3
  store i32 %56, ptr %57, align 4, !tbaa !3
  %58 = call i32 @_FortranACharacterCompareScalar1(ptr nonnull %14, ptr %31, i64 6, i64 %41)
  %59 = icmp eq i32 %58, 0
  %60 = zext i1 %59 to i32
  %61 = getelementptr i32, ptr %42, i64 4
  store i32 %60, ptr %61, align 4, !tbaa !3
  store ptr %42, ptr %0, align 8, !tbaa !7
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  store i8 14, ptr %.fca.4.gep, align 1, !tbaa !7
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  store i64 5, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %62 = call i1 @_FortranAAny(ptr nonnull %0, ptr nonnull @_QQcl.550e93d0b9a3aa7eae4c5202b0ddf7fd, i32 9, i32 1)
  %63 = icmp slt i32 %26, %34
  %64 = or i1 %63, %62
  call void @free(ptr %42)
  br i1 %64, label %.loopexit, label %65

65:                                               ; preds = %32
  %66 = call i32 @_FortranACharacterCompareScalar1(ptr %31, ptr nonnull %1, i64 %41, i64 6)
  %67 = icmp slt i32 %66, 0
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %14, ptr noundef nonnull align 1 dereferenceable(6) %12, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %12, ptr noundef nonnull align 1 dereferenceable(6) %10, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %10, ptr noundef nonnull align 1 dereferenceable(6) %8, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %8, ptr noundef nonnull align 1 dereferenceable(6) %1, i64 6, i1 false)
  %69 = call i64 @llvm.smin.i64(i64 %41, i64 6)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr align 1 %31, i64 %69, i1 false)
  %.not88 = icmp sgt i64 %40, 4
  br i1 %.not88, label %.loopexit, label %.loopexit.sink.split

70:                                               ; preds = %65
  %71 = call i32 @_FortranACharacterCompareScalar1(ptr %31, ptr nonnull %8, i64 %41, i64 6)
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %70
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %14, ptr noundef nonnull align 1 dereferenceable(6) %12, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %12, ptr noundef nonnull align 1 dereferenceable(6) %10, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %10, ptr noundef nonnull align 1 dereferenceable(6) %8, i64 6, i1 false)
  %74 = call i64 @llvm.smin.i64(i64 %41, i64 6)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %8, ptr align 1 %31, i64 %74, i1 false)
  %.not87 = icmp sgt i64 %40, 4
  br i1 %.not87, label %.loopexit, label %.loopexit.sink.split

75:                                               ; preds = %70
  %76 = call i32 @_FortranACharacterCompareScalar1(ptr %31, ptr nonnull %10, i64 %41, i64 6)
  %77 = icmp slt i32 %76, 0
  br i1 %77, label %78, label %80

78:                                               ; preds = %75
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %14, ptr noundef nonnull align 1 dereferenceable(6) %12, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %12, ptr noundef nonnull align 1 dereferenceable(6) %10, i64 6, i1 false)
  %79 = call i64 @llvm.smin.i64(i64 %41, i64 6)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %10, ptr align 1 %31, i64 %79, i1 false)
  %.not86 = icmp sgt i64 %40, 4
  br i1 %.not86, label %.loopexit, label %.loopexit.sink.split

80:                                               ; preds = %75
  %81 = call i32 @_FortranACharacterCompareScalar1(ptr %31, ptr nonnull %12, i64 %41, i64 6)
  %82 = icmp slt i32 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %80
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %14, ptr noundef nonnull align 1 dereferenceable(6) %12, i64 6, i1 false)
  %84 = call i64 @llvm.smin.i64(i64 %41, i64 6)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %12, ptr align 1 %31, i64 %84, i1 false)
  %.not85 = icmp sgt i64 %40, 4
  br i1 %.not85, label %.loopexit, label %.loopexit.sink.split

85:                                               ; preds = %80
  %86 = call i32 @_FortranACharacterCompareScalar1(ptr %31, ptr nonnull %14, i64 %41, i64 6)
  %87 = icmp slt i32 %86, 0
  br i1 %87, label %88, label %.loopexit

88:                                               ; preds = %85
  %89 = call i64 @llvm.smin.i64(i64 %41, i64 6)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %14, ptr align 1 %31, i64 %89, i1 false)
  %.not = icmp sgt i64 %40, 4
  br i1 %.not, label %.loopexit, label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %88, %83, %78, %73, %68
  %uglygep59.sink = phi ptr [ %uglygep74, %68 ], [ %uglygep71, %73 ], [ %uglygep67, %78 ], [ %uglygep63, %83 ], [ %uglygep59, %88 ]
  call void @llvm.memset.p0.i64(ptr align 1 %uglygep59.sink, i8 32, i64 %38, i1 false), !tbaa !3
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.sink.split, %88, %83, %78, %73, %68, %85, %32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
  br i1 %exitcond.not, label %90, label %32

90:                                               ; preds = %.loopexit
  %indvars.iv.next77 = add nuw nsw i64 %indvars.iv76, 1
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond79.not = icmp eq i64 %indvar.next, %28
  br i1 %exitcond79.not, label %._crit_edge, label %.preheader

._crit_edge:                                      ; preds = %90, %23
  %91 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.286129, i64 3, ptr null, i32 -1, ptr nonnull @_QQcl.550e93d0b9a3aa7eae4c5202b0ddf7fd, i32 35)
  %92 = load i32, ptr %2, align 4, !tbaa !3
  %93 = sext i32 %92 to i64
  %94 = add nsw i64 %93, -1
  %95 = getelementptr [5 x [6 x i8]], ptr %1, i64 0, i64 %94
  %96 = call i1 @_FortranAioOutputAscii(ptr %91, ptr %95, i64 6)
  %97 = call i32 @_FortranAioEndIoStatement(ptr %91)
  ret void
}

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

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

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

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

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

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

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
