#include <iostream>
#include <vector>
#include  <set>
#include <cstdlib>
#include <algorithm>
#define MAXA 1000000
#define ll long long
using namespace std;

vector<int> divs[MAXA+2];
int smallest_prime[MAXA+2];
bool isprime[MAXA+2];
int counts[MAXA+2];
int moebius[MAXA+2];

int g(int N,int x) {
    int ans2=0;
    for(int y : divs[N]) {
        
        ans2 += (x/y)*moebius[y];
    }
    return -ans2;
}

int main() {

   
    for(int i=2;i<=MAXA;i++) {
        for(int j=1;j<=MAXA/i;j++) {
            divs[i*j].push_back(i);
        }
    }
    
    for(int i=1;i<=MAXA;i++) {
        smallest_prime[i]=-1;
        isprime[i]=true;
        counts[i]=0;
    }
    
    for(int i=2;i<=MAXA;i++) {
        if(smallest_prime[i]==-1) {
            for(int j=i;j<=MAXA/i;j++) {
                smallest_prime[j*i]=i;
                isprime[j*i]=false;
            }
            smallest_prime[i]=i;
        }
    }
    
    moebius[1]=1;
    for(int i=2;i<=MAXA;i++) {
        int x=i;
        int p=smallest_prime[i];
        while(x%p==0) {
            x/=p;
        }
        if(x*p==i) {
            moebius[i]=-moebius[x];
        } else {
            moebius[i]=0;
        }
        
        
    }
    


    int L,R;
    cin>>L>>R;
    ll ans = 0;
    for(int y=L;y<=R;y++) {
        int curr = y-L;
        for(int d : divs[y]) {
            if (d >= L && d < y) curr--;
        }
        curr -= y-L-g(y,y-1)+g(y,L-1);
        ans += curr;
    }
    cout << 2*ans << endl;

}
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
//mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,T y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,T y){if(x>y)x=y;}
inline int read(){
  #define nc getchar()
  int x=0;char c=nc;bool f=0;
  while(c<48)f|=c=='-',c=nc;
  while(c>47)x=x*10+(c^48),c=nc;
  return f?-x:x;
  #undef nc
}

typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;
const int maxn=2e5+10;
int n,k;vi E[maxn];

int mid;
int res,F[maxn],G[maxn];

void dfs(int u,int f){
  F[u]=1e9,G[u]=-1;
  for(int v:E[u])if(v!=f){
    dfs(v,u);
    chkmin(F[u],F[v]+1);
  }
  for(int v:E[u])if(v!=f){
    if(G[v]+F[u]>=mid){
      chkmax(G[u],G[v]+1);
    }
  }
  if(F[u]>mid)chkmax(G[u],0);
  if(G[u]==mid){
    res++,F[u]=0,G[u]=-1;
  }
}

void solve(){
  cin>>n>>k;
  rep(i,2,n){
    int u=read(),v=read();E[u].push_back(v),E[v].push_back(u);
  }
  int l=1,r=n;
  while(l<r){
    mid=(l+r)/2,res=0,dfs(1,0);
    if(G[1]!=-1)res++;
    res<=k?r=mid:l=mid+1;
  }
  cout<<l<<endl;
}

signed main(){
//  int T=read();
//  while(T--)solve();
  solve();
  return 0;
 }
