#import <stdio.h>
#import <stdlib.h>
typedef long long INT;

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

int main(int argc, const char * argv[]) {
    int N;
    INT x;
    scanf("%d %lld", &N, &x);
    INT *numbers = (INT*)malloc(N * sizeof(INT));
    
    INT n;
    int i = 0;
    while (scanf("%lld", &n) != EOF) {
        numbers[i] = n;
        i++;
    }
    
    qsort(numbers, N, sizeof(INT), compare_int);
    i=0;
    int count=0;
    while (x>0 && i<N) {
        if (x>=numbers[i]) {
            x -= numbers[i];
            count++;
        } else {
            x=0;
            break;
        }
        i++;
    }
    if (x>0) {
        count--;
    }

    printf("%d", count);
    
    free(numbers);
    return 0;
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_438/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_438/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"%d %lld\00", align 1
@.str.1 = private unnamed_addr constant [5 x i8] c"%lld\00", align 1
@.str.2 = private unnamed_addr constant [3 x i8] c"%d\00", align 1

; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(argmem: read) uwtable
define dso_local i32 @compare_int(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i64, ptr %a, align 8, !tbaa !5
  %1 = load i64, ptr %b, align 8, !tbaa !5
  %sub = sub nsw i64 %0, %1
  %conv = trunc i64 %sub to i32
  ret i32 %conv
}

; Function Attrs: minsize nounwind optsize uwtable
define dso_local i32 @main(i32 noundef %argc, ptr nocapture noundef readnone %argv) local_unnamed_addr #1 {
entry:
  %N = alloca i32, align 4
  %x = alloca i64, align 8
  %n = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %x) #7
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N, ptr noundef nonnull %x) #8
  %0 = load i32, ptr %N, align 4, !tbaa !9
  %conv = sext i32 %0 to i64
  %mul = shl nsw i64 %conv, 3
  %call1 = call noalias ptr @malloc(i64 noundef %mul) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #7
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ 0, %entry ]
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %n) #8
  %cmp.not = icmp eq i32 %call2, -1
  br i1 %cmp.not, label %while.end, label %while.body

while.body:                                       ; preds = %while.cond
  %1 = load i64, ptr %n, align 8, !tbaa !5
  %arrayidx = getelementptr inbounds i64, ptr %call1, i64 %indvars.iv
  store i64 %1, ptr %arrayidx, align 8, !tbaa !5
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  br label %while.cond

while.end:                                        ; preds = %while.cond
  %2 = load i32, ptr %N, align 4, !tbaa !9
  %conv4 = sext i32 %2 to i64
  call void @qsort(ptr noundef %call1, i64 noundef %conv4, i64 noundef 8, ptr noundef nonnull @compare_int) #10
  %3 = load i32, ptr %N, align 4
  %x.promoted = load i64, ptr %x, align 8, !tbaa !5
  %4 = sext i32 %3 to i64
  br label %while.cond5

while.cond5:                                      ; preds = %if.then, %while.end
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %if.then ], [ 0, %while.end ]
  %sub39 = phi i64 [ %sub, %if.then ], [ %x.promoted, %while.end ]
  %cmp6 = icmp sgt i64 %sub39, 0
  %cmp8 = icmp slt i64 %indvars.iv43, %4
  %5 = select i1 %cmp6, i1 %cmp8, i1 false
  br i1 %5, label %while.body10, label %while.end19.loopexit

while.body10:                                     ; preds = %while.cond5
  %arrayidx12 = getelementptr inbounds i64, ptr %call1, i64 %indvars.iv43
  %6 = load i64, ptr %arrayidx12, align 8, !tbaa !5
  %cmp13.not = icmp slt i64 %sub39, %6
  br i1 %cmp13.not, label %if.else, label %if.then

if.then:                                          ; preds = %while.body10
  %sub = sub nsw i64 %sub39, %6
  store i64 %sub, ptr %x, align 8, !tbaa !5
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  br label %while.cond5

if.else:                                          ; preds = %while.body10
  store i64 0, ptr %x, align 8, !tbaa !5
  br label %while.end19

while.end19.loopexit:                             ; preds = %while.cond5
  %7 = icmp sgt i64 %sub39, 0
  %8 = sext i1 %7 to i32
  br label %while.end19

while.end19:                                      ; preds = %while.end19.loopexit, %if.else
  %cmp20 = phi i32 [ %8, %while.end19.loopexit ], [ 0, %if.else ]
  %indvars47 = trunc i64 %indvars.iv43 to i32
  %spec.select = add nsw i32 %cmp20, %indvars47
  %call24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %spec.select) #8
  call void @free(ptr noundef %call1) #10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %x) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #7
  ret i32 0
}

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

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

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

; Function Attrs: minsize nofree optsize
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #5

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

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

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

attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(argmem: read) 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 = { minsize nounwind optsize 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { minsize nofree nounwind optsize "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 = { minsize mustprogress nofree nounwind optsize willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { minsize nofree optsize "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 #6 = { minsize mustprogress nounwind optsize willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { nounwind }
attributes #8 = { minsize optsize }
attributes #9 = { minsize nounwind optsize allocsize(0) }
attributes #10 = { minsize nounwind optsize }

!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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
