#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int n,K,i,j,k,l,L,R,Mid,sum,s1,s2;
int a[400001][2],ls[200001],len;
int f[200001];

void New(int x,int y) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;}
void dfs(int Fa,int t)
{
	int i,s1=n+1,s2=-n-1;
	bool bz=0;
	f[t]=0;
	for (i=ls[t]; i; i=a[i][1])
	if (a[i][0]!=Fa)
	{
		dfs(t,a[i][0]),bz=1;
		s1=min(s1,f[a[i][0]]+1);
		s2=max(s2,f[a[i][0]]+1);
		f[t]=max(f[t],f[a[i][0]]+1);
	}
	if (bz)
	{
		if (s1+1<0 && s1+1+s2<=0) f[t]=s1;
		else
		{
			f[t]=s2;
			if (f[t]==Mid)
			f[t]=-Mid-1,++sum;
		}
	}
}

int main()
{
	#ifdef file
	freopen("e.in","r",stdin);
	#endif
	
	scanf("%d%d",&n,&K);
	fo(i,1,n-1) scanf("%d%d",&j,&k),New(j,k),New(k,j);
	
	L=1,R=n;
	while (L<R)
	{
		Mid=(L+R)/2;
		sum=0;
		dfs(0,1);
		s1=n+1,s2=-n-1;
		for (i=ls[1]; i; i=a[i][1])
		{
			s1=min(s1,f[a[i][0]]+1);
			s2=max(s2,f[a[i][0]]+1);
		}
		if (!(f[1]<0 || s1+1+s2<=0)) ++sum;
		
		if (sum>K) L=Mid+1; else R=Mid;
	}
	printf("%d\n",L);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
//Target for Pupil
//Implementation and Data structures
//Prodip sarker(student_ip)
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define al(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int>  vi;
typedef vector<ll>   vll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	long long unsigned a,b,c,x,y,n,i,t,tmp,d,e,f,p;
	cin>>x>>y>>a>>b;
	ll sum=0;
	while(x<y)
	{
//		cout<<x<<"\n";
		if(LLONG_MAX/x >= a &&x*a<x+b&&(x*a<y))
		{
			sum++;
			x=x*a;
		}
		else
		{
			y-=1;
			sum+=(y-x)/b;
			break;
		}
	}
	cout<<sum<<endl;

	return 0;
}