def f(sum,xs,m) return 0 if (sum>m) if(xs.empty? == true) return sum else e=xs.shift res=0 res=f(sum,xs,m) res=[res,f(sum+e,xs,m)].max xs.unshift(e) return res end end n,m=gets.split.map{|e| e.to_i} xs=STDIN.read.split.map{|e| e.to_i} puts f(0,xs,m)