#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
#define repr(i,n) for(int i=2;i*i<=(n);++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define pob pop_back()
#define Mod (ll)(1e9+7)
#define mod (ll)(998244353)
#define setp(x) setprecision((ll)(n))
#define INF (ll)(1000000000000000000)
using namespace std;
using vi=vector<int>;
using vc=vector<char>;
using vl=vector<long long>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vvc=vector<vc>;
using vpl=vector<pair<ll,ll>>;
using vs=vector<string>;
using pii=pair<int, int>;
using pll=pair<ll,ll>;

int main(){
  ll n; cin>>n;
  vi p(n);
  rep(i,n) cin>>p[i];
  sort(all(p));
  ll sum=1,res=0;
  rep(i,n-1){
   if(p[i]==p[i+1]) sum++;
   else {
    res+=sum*(sum-1)/2;
    sum=1;
   }
  }
  res+=sum*(sum-1)/2;
  sum=1;
  cout<<n*(n-1)/2-res<<endl;
  return 0;
}
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int n,k,num=0;
vector<int>e[1000010];
int dfs(int x,int pre,int lim)
{
	int now=0,minn=1e16,son=0;
	for(auto i:e[x])
	{
		if(i==pre)continue;
		int nxt=dfs(i,x,lim);
		son++;
		now=max(now,nxt+1);
		minn=min(minn,nxt+1);
	}
	// cout<<x<<":"<<now<<","<<minn<<","<<son<<"\n";
	if(son!=1&&now+minn<=2*lim+1)now=minn;
	if(x!=1&&e[x].size()==1)return lim+1;
	if(now==2*lim+1||(x==1&&now>lim))num++,now=0;
	return now;
}
bool check(int x)
{
	num=0;
	// cout<<x<<":"<<"\n-------------------\n";
	dfs(1,1,x);
	// cout<<"num="<<num<<"\n"<<"--------------------\n";
	return num<=k;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=qr,k=qr;
	for(int i=1;i<n;i++)
	{
		int x=qr,y=qr;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	int l=1,r=n,ans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}