#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define endl "\n"
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e2+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x&(-x))
using namespace std;
ll n,m,k;
ll a[maxn];
ll dp[maxn];
int vis[maxn];
ll ans = 0;
ll sum[maxn];
int r;
void dfs(ll sum1,int r){
    if(sum1 > k)
       return ;
    ans = max(ans,sum1);
    if(sum[r] + sum1 <= k){
        ans = max(sum[r] + sum1,ans);
        return ;
    }
    if(ans == k){
        return ;
    }
    for(int i = 1; i<=r; i++){
        if(vis[i] == 1)
            continue;
        if(sum1 + a[i] > k){
            return ;
        }
        vis[i] = 1;
        dfs(sum1+a[i],i-1);
        vis[i] = 0;
    }
}
void run_case(){
    cin>>n>>k;
    ll sum1 = 0;
    for(int i = 1; i<=n; i++){
        cin>>a[i];
        sum1 += a[i];
    }
    if(sum1 <= k){
        cout<<sum1<<endl;
        return ;
    }
    sort(a+1,a+n+1);
    for(int i = 1; i<=n; i++)
        sum[i] = sum[i-1] + a[i];
    for(int i = n; i>=1; i--){
        vis[i] = 1;
        dfs(a[i],i-1);
        vis[i] = 0;
    }
    cout<<ans<<endl;
}


int main(){
    ios;
    run_case();
}

//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
#define lc (x<<1)
#define rc ((x<<1)|1)
using namespace std;
int n,m,d[200005];
V<int> v[200005];
int dfs(int x,int len,int fa){
	int t=-1e9;
	if(v[x].size()==1&&x!=1){
		t=0;
	}
	int re=0,mi=-1e9;
	for(auto u:v[x])if(u!=fa){
		re+=dfs(u,len,x);
		gmax(t,d[u]+1);
		if(d[u]<0)gmax(mi,-d[u]-1);
	}
	if(mi>=t+1){
		d[x]=-mi;
	}else d[x]=t;
	if(t==len||(x==1&&d[x]>=0)){
		d[x]=-len-1;re++;
	}
	RE re; 
}
bool check(int x){
	RE dfs(1,x,-1)<=m;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	FOR(i,2,n){
		int x,y;
		cin>>x>>y;
		v[x].PB(y);
		v[y].PB(x);
	}
	int ans=n-1,l=0,r=n-1,mid;
	while(r>=l){
		mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;r=mid-1;
		}else l=mid+1;
	}
	cout<<ans;
	RE 0;
}








