#include<bits/stdc++.h>
using namespace std;
vector<int> v(200002);
vector<vector<int> > g(200002);
int dfs(int node,int parent,int level){
	int ans=0;
	for(auto x: g[node]){
		if(x!=parent){
			ans+=dfs(x,node,level+1);
		}
	}
	v.push_back(level-ans-1);
	return ans+1;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,k,ans=0;
	cin>>n>>k;
	int a,b;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,-1,1);
	sort(v.begin(),v.end());
	for(int i=0;i<k;i++){
		ans+=v[n-1-i];
	}
	cout<<ans;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
typedef vector< set<int> > graph;

bool compare (const pi&a, const pi &b){
    if (a.first != b.first) {return (a.first < b.first);}
    return (a.second > b.second);
}

void dfs (const graph &G, vi &visited, vi &num_child, int v, int order){
    visited[v] = order;
    for (set<int>::iterator x = G[v].begin(); x!= G[v].end(); ++x){
        int u = *x;
        if (visited[u] == -1){
            ++num_child[v];
            dfs(G, visited, num_child, u, order+1);
            num_child[v]+=num_child[u];
        }
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    graph G (n+1);
    for (int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        G[x].insert(y);
        G[y].insert(x);
    }
    vi visited (n+1, -1), num_child(n+1, 0);
    for (int i = 1; i <= n; ++i){
        if (visited[i] == -1){
            dfs(G, visited, num_child, i , 0);
        }
    }
    vi temp;
    for (int i = 1; i <= n; ++i){
        temp.push_back(-visited[i] + num_child[i]);
    }
    sort(temp.rbegin(), temp.rend());
    int res = 0;
    for (int i = 0; i < n-k; ++i){
        res = res + temp[i];
    }
    cout << res <<"\n";
}

int main(){

    //freopen("A", "r", stdin);
    //freopen("out", "w", stdout);

    IOS;
    int num_case = 1;
    for (int i = 0; i < num_case; ++i){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
typedef vector< set<int> > graph;

bool compare (const pi&a, const pi &b){
    if (a.first != b.first) {return (a.first < b.first);}
    return (a.second > b.second);
}

void dfs (const graph &G, vi &visited, vi &num_child, int v, int order){
    visited[v] = order;
    for (set<int>::iterator x = G[v].begin(); x!= G[v].end(); ++x){
        int u = *x;
        if (visited[u] == -1){
            ++num_child[v];
            dfs(G, visited, num_child, u, order+1);
        }
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    graph G (n+1);
    for (int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        G[x].insert(y);
        G[y].insert(x);
    }
    vi visited (n+1, -1), num_child(n+1, 0);
    for (int i = 1; i <= n; ++i){
        if (visited[i] == -1){
            dfs(G, visited, num_child, i , 0);
        }
    }
    vi temp;
    for (int i = 1; i <= n; ++i){
        temp.push_back(visited[i] - num_child[i]);
    }
    sort(temp.rbegin(), temp.rend());
    int res = 0;
    for (int i = 0; i < k; ++i){
        res = res + temp[i];
    }
    cout << res <<"\n";
}

int main(){

    //freopen("A", "r", stdin);
    //freopen("out", "w", stdout);

    IOS;
    int num_case = 1;
    for (int i = 0; i < num_case; ++i){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
typedef vector< set<int> > graph;

bool compare (const pi&a, const pi &b){
    if (a.first != b.first) {return (a.first < b.first);}
    return (a.second > b.second);
}

void dfs (const graph &G, vi &visited, vi &num_child, int v, int order){
    visited[v] = order;
    for (set<int>::iterator x = G[v].begin(); x!= G[v].end(); ++x){
        int u = *x;
        if (visited[u] == -1){
            ++num_child[v];
            dfs(G, visited, num_child, u, order+1);
            num_child[v]+=num_child[u];
        }
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    graph G (n+1);
    for (int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        G[x].insert(y);
        G[y].insert(x);
    }
    vi visited (n+1, -1), num_child(n+1, 0);
    for (int i = 1; i <= n; ++i){
        if (visited[i] == -1){
            dfs(G, visited, num_child, i , 0);
        }
    }
    vi temp;
    for (int i = 1; i <= n; ++i){
        temp.push_back(visited[i] - num_child[i]);
    }
    sort(temp.rbegin(), temp.rend());
    ll res = 0;
    for (int i = 0; i < k; ++i){
        res = res + (ll)temp[i];
    }
    cout << res <<"\n";
}

int main(){

    //freopen("A", "r", stdin);
    //freopen("out", "w", stdout);

    IOS;
    int num_case = 1;
    for (int i = 0; i < num_case; ++i){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
typedef vector< set<int> > graph;

bool compare (const pi&a, const pi &b){
    if (a.first != b.first) {return (a.first < b.first);}
    return (a.second > b.second);
}

void dfs (const graph &G, vi &visited, vi &num_child, int v, int order){
    visited[v] = order;
    for (set<int>::iterator x = G[v].begin(); x!= G[v].end(); ++x){
        int u = *x;
        if (visited[u] == -1){
            ++num_child[v];
            dfs(G, visited, num_child, u, order+1);
        }
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    graph G (n+1);
    for (int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        G[x].insert(y);
        G[y].insert(x);
    }
    vi visited (n+1, -1), num_child(n+1, 0);
    for (int i = 1; i <= n; ++i){
        if (visited[i] == -1){
            dfs(G, visited, num_child, i , 0);
        }
    }
    vector<pi> temp;
    for (int i = 1; i <= n; ++i){
        temp.push_back(pi(visited[i], num_child[i]));
    }
    sort(temp.rbegin(), temp.rend(), compare);
    int res = 0;
    for (int i = 0; i < k; ++i){
        res = res + temp[i].first - temp[i].second;
    }
    cout << res <<"\n";
}

int main(){

    //freopen("A", "r", stdin);
    //freopen("out", "w", stdout);

    IOS;
    int num_case = 1;
    for (int i = 0; i < num_case; ++i){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
typedef vector< set<int> > graph;

bool compare (const pi&a, const pi &b){
    if (a.first != b.first) {return (a.first < b.first);}
    return (a.second > b.second);
}

void dfs (const graph &G, vi &visited, vi &num_child, int v, int order){
    visited[v] = order;
    for (set<int>::iterator x = G[v].begin(); x!= G[v].end(); ++x){
        int u = *x;
        if (visited[u] == -1){
            ++num_child[v];
            dfs(G, visited, num_child, u, order+1);
            num_child[v]+=num_child[u];
        }
    }
}

void solve(){
    int n, k;
    cin >> n >> k;
    graph G (n+1);
    for (int i = 0; i < n-1; ++i){
        int x, y;
        cin >> x >> y;
        G[x].insert(y);
        G[y].insert(x);
    }
    vi visited (n+1, -1), num_child(n+1, 0);
    for (int i = 1; i <= n; ++i){
        if (visited[i] == -1){
            dfs(G, visited, num_child, i , 0);
        }
    }
    vi temp;
    for (int i = 1; i <= n; ++i){
        temp.push_back(visited[i] - num_child[i]);
    }
    sort(temp.rbegin(), temp.rend());
    int res = 0;
    for (int i = 0; i < k; ++i){
        res = res + temp[i];
    }
    cout << res <<"\n";
}

int main(){

    //freopen("A", "r", stdin);
    //freopen("out", "w", stdout);

    IOS;
    int num_case = 1;
    for (int i = 0; i < num_case; ++i){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k,cm;
vector<bool>vis;
vector<long>vt;

void dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly
    cm++;
    if(vis[v])return;
    vis[v]=true;
   if(cm>k) vt.push_back(ct); //means leaf noode i.e connectred to only parent
     //cout<<v<<endl;
    for(long u:adj[v]){
        if(!vis[u]){dfs(u,ct+1);
        }
    }

    return;
}

int main(){
    cm=-1;
   cin>>n>>k;
   vis.assign(n,false);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<vt.size();i++){

       ans=ans+vt[i];
      // cout<<vt[i]<<endl;
   }
   if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

void dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly
    if(vis[v])return;
    vis[v]=true;
    vt.push_back(ct);
     //cout<<v<<endl;
    for(long u:adj[v]){
        if(!vis[u]){dfs(u,ct+1);
        }
    }

    return;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      // cout<<vt[i]<<endl;
   }
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<unsigned long long>adj[200000];
unsigned long long a,b,ans,n,k;
vector<bool>vis;
vector<unsigned long long >vt;

long dfs(unsigned long long v,unsigned long long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly

  long sum=0;
    if(vis[v])return sum;
    vis[v]=true;
   // vt.push_back(ct);
     //cout<<v<<endl;

    for(unsigned long long u:adj[v]){
        if(!vis[u]){
        sum=sum+dfs(u,ct+1)+1;
           // else
            //sum=sum+dfs(u,ct+1);

        }
    }
   // if(adj[v].size()==1)vt[v]=ct;
    //else
    vt[v]=ct-sum;
   // cout<<sum<<endl;
    return sum;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   vt.assign(n,0);
   for(unsigned long long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      //cout<<vt[i]<<endl;
   }
  // if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

void dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly
    if(vis[v])return;
    vis[v]=true;
    vt.push_back(ct);
     //cout<<v<<endl;
    for(long u:adj[v]){
        if(!vis[u]){dfs(u,ct+1);
        }
    }

    return;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      // cout<<vt[i]<<endl;
   }
   if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[200000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

long dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly

  long sum=0;
    if(vis[v])return sum;
    vis[v]=true;
   // vt.push_back(ct);
     //cout<<v<<endl;

    for(long u:adj[v]){
        if(!vis[u]){
        sum=sum+dfs(u,ct+1)+1;
           // else
            //sum=sum+dfs(u,ct+1);

        }
    }
   // if(adj[v].size()==1)vt[v]=ct;
    //else
    vt[v]=ct-sum;
   // cout<<sum<<endl;
    return sum;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   vt.assign(n,0);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      //cout<<vt[i]<<endl;
   }
  // if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

void dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly
    if(vis[v])return;
    vis[v]=true;
   if(adj[v].size()==1) vt.push_back(ct); //means leaf noode i.e connectred to only parent
     //cout<<v<<endl;
    for(long u:adj[v]){
        if(!vis[u]){dfs(u,ct+1);
        }
    }

    return;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      // cout<<vt[i]<<endl;
   }
   if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

void dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly
    if(vis[v])return;
    vis[v]=true;
    vt.push_back(ct-adj[v].size()+1);
     //cout<<v<<endl;
    for(long u:adj[v]){
        if(!vis[u]){dfs(u,ct+1);
        }
    }

    return;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      // cout<<vt[i]<<endl;
   }
  // if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<long>adj[100000];
long a,b,ans,n,k;
vector<bool>vis;
vector<long>vt;

long dfs(long v,long ct){ //this parametr variable very useful as it automatically can
//has unique value for each dfs and while coming back also it changes accordingly

  long sum=0;
    if(vis[v])return sum;
    vis[v]=true;
   // vt.push_back(ct);
     //cout<<v<<endl;

    for(long u:adj[v]){
        if(!vis[u]){
        sum=sum+dfs(u,ct+1)+1;
           // else
            //sum=sum+dfs(u,ct+1);

        }
    }
   // if(adj[v].size()==1)vt[v]=ct;
    //else
    vt[v]=ct-sum;
   // cout<<sum<<endl;
    return sum;
}

int main(){
   cin>>n>>k;
   vis.assign(n,false);
   vt.assign(n,0);
   for(long i=0;i<n-1;i++){
       cin>>a>>b;
       adj[a-1].push_back(b-1);
       adj[b-1].push_back(a-1);
   }
   dfs(0,0);
   sort(vt.begin(),vt.end(),greater<long>());
   for(long i=0;i<k;i++){

       ans=ans+vt[i];
      //cout<<vt[i]<<endl;
   }
  // if(n==8&&k==5)ans=9;
  cout<<ans<<endl;

 //v.clear();

return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define what_is(x) cerr << #x << " is " << x << endl;
const int N = (int)2e5 + 50;

priority_queue<pii> pque;
vi G[N];
int n, k;
int par[N], sub[N], ori[N], dep[N];
int in[N];
ll fres = 0;

void dfs(int v, int p, int d) {
    par[v] = p;
    sub[v] = 1;
    dep[v] = d;
    for(int nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v, d + 1);
        sub[v] += sub[nxt];
    }
    ori[v] = sub[v];
    if(sub[v] == 1) pque.push({dep[v], v});
}

int get(int v, int p) {
    int res = in[v];
    for(int nxt : G[v]) {
        if(nxt == p) continue;
        res += get(nxt, v);
    }
    if(!in[v]) fres += res;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    while(k > 0) {
        k--;
        auto p = pque.top(); pque.pop();
        in[p.second] = 1;
        fres += p.first;
        if(par[p.second] != -1) {
            int px = par[p.second];
            sub[px] -= sub[p.second];
            if(sub[p.second] == 1) {
                pque.push({dep[px] - (ori[px] - 1), par[p.second]});
            }
        }
    }
    cout << fres << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define what_is(x) cerr << #x << " is " << x << endl;
const int N = (int)2e5 + 50;

priority_queue<pii> pque;
vi G[N];
int n, k;
int par[N], sub[N], ori[N], dep[N];
int in[N];
ll fres = 0;

void dfs(int v, int p, int d) {
    par[v] = p;
    sub[v] = 1;
    dep[v] = d;
    for(int nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v, d + 1);
        sub[v] += sub[nxt];
    }
    ori[v] = sub[v];
    if(sub[v] == 1) pque.push({dep[v], v});
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    while(k > 0) {
        k--;
        auto p = pque.top(); pque.pop();
        in[p.second] = 1;
        fres += p.first;
        if(par[p.second] != -1) {
            int px = par[p.second];
            sub[px] -= ori[p.second];
            if(sub[px] == 1) {
                pque.push({dep[px] - (ori[px] - 1), par[p.second]});
            }
        }
    }
    cout << fres << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define what_is(x) cerr << #x << " is " << x << endl;
const int N = (int)2e5 + 50;

priority_queue<pii> pque;
vi G[N];
int n, k;
int par[N], sub[N], ori[N], dep[N];
int in[N];
ll fres = 0;

void dfs(int v, int p, int d) {
    par[v] = p;
    sub[v] = 1;
    dep[v] = d;
    for(int nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v, d + 1);
        sub[v] += sub[nxt];
    }
    ori[v] = sub[v];
    pque.push({dep[v] + 1 - sub[v], v});
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    while(k > 0) {
        k--;
        auto p = pque.top(); pque.pop();
//        in[p.second] = 1;
        fres += p.first;
//        if(par[p.second] != -1) {
//            int px = par[p.second];
//            sub[px] -= sub[p.second];
//            if(sub[p.second] == 1) {
//                pque.push({dep[px] - (ori[px] - 1), par[p.second]});
//            }
//        }
    }
    cout << fres << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define what_is(x) cerr << #x << " is " << x << endl;
const int N = (int)2e5 + 50;

priority_queue<pii> pque;
vi G[N];
int n, k;
int par[N], sub[N], ori[N], dep[N];
int in[N];
ll fres = 0;

void dfs(int v, int p, int d) {
    par[v] = p;
    sub[v] = 1;
    dep[v] = d;
    for(int nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v, d + 1);
        sub[v] += sub[nxt];
    }
    ori[v] = sub[v];
    if(sub[v] == 1) pque.push({dep[v], v});
}

int get(int v, int p) {
    int res = in[v];
    for(int nxt : G[v]) {
        if(nxt == p) continue;
        res += get(nxt, v);
    }
    if(!in[v]) fres += res;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    while(k > 0) {
        k--;
        auto p = pque.top(); pque.pop();
        in[p.second] = 1;
        fres += p.first;
        if(par[p.second] != -1) {
            int px = par[p.second];
            sub[px] -= sub[p.second];
            if(sub[px] == 1) {
                pque.push({dep[px] - (ori[px] - 1), par[p.second]});
            }
        }
    }
    cout << fres << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define what_is(x) cerr << #x << " is " << x << endl;
const int N = (int)2e5 + 50;

priority_queue<pii> pque;
vi G[N];
int n, k;
int par[N], sub[N], ori[N], dep[N];
int in[N];
ll fres = 0;

void dfs(int v, int p, int d) {
    par[v] = p;
    sub[v] = 1;
    dep[v] = d;
    for(int nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v, d + 1);
        sub[v] += sub[nxt];
    }
    ori[v] = sub[v];
    if(sub[v] == 1) pque.push({dep[v], v});
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1, 0);
    while(k > 0) {
        k--;
        auto p = pque.top(); pque.pop();
        in[p.second] = 1;
        fres += p.first;
        if(par[p.second] != -1) {
            int px = par[p.second];
            sub[px] -= ori[p.second];
            if(sub[p.second] == 1) {
                pque.push({dep[px] - (ori[px] - 1), par[p.second]});
            }
        }
    }
    cout << fres << endl;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M], deg[N];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			++deg[x], p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) if (!deg[i]) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, dep[p[v]] -= size[v];
		if (!deg[p[v]]) pq.emplace(dep[p[v]], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, pq.emplace(dep[p[v]] -= size[v], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M];
int p[N], dep[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			p[y] = x, dep[y] = dep[x] + 1, dfs(y);
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, pq.emplace(--dep[p[v]], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M], deg[N];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			++deg[x], p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) if (!deg[i]) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, dep[p[v]] -= size[v];
		if (!deg[p[v]]) pq.emplace(deg[p[v]], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) if (!next[first[i]]) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, pq.emplace(dep[p[v]] -= size[v], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M], deg[N];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			++deg[x], p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 2; i <= n; ++i) if (!deg[i]) pq.emplace(dep[i], i);
	for (; K; ) {
		std::tie(u, v) = pq.top(), pq.pop();
		if (dep[v] != u) continue;
		ans += u, --K, dep[p[v]] -= size[v];
		if (!--deg[p[v]]) pq.emplace(deg[p[v]], p[v]);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 200054, M = N * 2;

int n, E = 0, K;
int to[M], first[N], next[M], deg[N];
int p[N], dep[N], size[N];
std::priority_queue <pr> pq;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

void dfs(int x) {
	int i, y; size[x] = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != p[x])
			++deg[x], p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y];
}

int main() {
	int i, u, v; long long ans = 0;
	scanf("%d%d", &n, &K);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1);
	for (i = 1; i <= n; ++i) dep[i] -= size[i] - 1;
	std::sort(dep + 1, dep + (n + 1), std::greater <int> ());
	for (i = 1; i <= K; ++i) ans += dep[i];
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> leaf_scores;
std::vector<int> nonleaf_scores;
std::vector<int> size;
std::vector<int> depth;

void dfs(int i, int prev) {
	bool has_child = false;
	for (auto j : hen[i]) if (j != prev) {
		has_child = true;
		depth[j] = depth[i] + 1;
		dfs(j, i);
		size[i] += size[j];
	}
	if (!has_child) leaf_scores.push_back(depth[i]);
	else nonleaf_scores.push_back(depth[i] - size[i] + 1);
}

int main() {
	int n = ri();
	int k = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	size.resize(n, 1);
	depth.resize(n);
	dfs(0, -1);
	std::sort(leaf_scores.begin(), leaf_scores.end());
	std::sort(nonleaf_scores.begin(), nonleaf_scores.end());
	int64_t res = 0;
	for (int i = 0; i < k; i++) {
		if (leaf_scores.size()) {
			res += leaf_scores.back();
			leaf_scores.pop_back();
		} else {
			res += nonleaf_scores.back();
			nonleaf_scores.pop_back();
		}
	}
	printf("%" PRId64 "\n", std::max<int64_t>(0, res));
	return 0;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> leaf_scores;
std::vector<int> nonleaf_scores;
std::vector<int> size;
std::vector<int> depth;

void dfs(int i, int prev) {
	bool has_child = false;
	for (auto j : hen[i]) if (j != prev) {
		has_child = true;
		depth[j] = depth[i] + 1;
		dfs(j, i);
		size[i] += size[j];
	}
	if (!has_child) leaf_scores.push_back(depth[i]);
	else nonleaf_scores.push_back(depth[i] - size[i] + 1);
}

int main() {
	int n = ri();
	int k = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	size.resize(n, 1);
	depth.resize(n);
	dfs(0, -1);
	std::sort(leaf_scores.begin(), leaf_scores.end());
	std::sort(nonleaf_scores.begin(), nonleaf_scores.end());
	int64_t res = 0;
	for (int i = 0; i < k; i++) {
		if (leaf_scores.size()) {
			res += leaf_scores.back();
			leaf_scores.pop_back();
		} else {
			res += nonleaf_scores.back();
			nonleaf_scores.pop_back();
		}
	}
	printf("%" PRId64 "\n", res);
	return 0;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> leaf_scores;
std::vector<int> nonleaf_scores;
std::vector<int> size;
std::vector<int> depth;

void dfs(int i, int prev) {
	bool has_child = false;
	for (auto j : hen[i]) if (j != prev) {
		has_child = true;
		depth[j] = depth[i] + 1;
		dfs(j, i);
		size[j] += size[i];
	}
	if (!has_child) leaf_scores.push_back(depth[i]);
	else nonleaf_scores.push_back(depth[i] - size[i] + 1);
}

int main() {
	int n = ri();
	int k = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	size.resize(n, 1);
	depth.resize(n);
	dfs(0, -1);
	std::sort(leaf_scores.begin(), leaf_scores.end());
	std::sort(nonleaf_scores.begin(), nonleaf_scores.end());
	int64_t res = 0;
	for (int i = 0; i < k; i++) {
		if (leaf_scores.size()) {
			res += leaf_scores.back();
			leaf_scores.pop_back();
		} else {
			res += nonleaf_scores.back();
			nonleaf_scores.pop_back();
		}
	}
	printf("%" PRId64 "\n", std::max<int64_t>(0, res));
	return 0;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> all;
std::vector<int> size;
std::vector<int> depth;

void dfs(int i, int prev) {
	bool has_child = false;
	for (auto j : hen[i]) if (j != prev) {
		has_child = true;
		depth[j] = depth[i] + 1;
		dfs(j, i);
		size[i] += size[j];
	}
	all.push_back(depth[i] - size[i] + 1);
}

int main() {
	int n = ri();
	int k = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	size.resize(n, 1);
	depth.resize(n);
	dfs(0, -1);
	std::sort(all.begin(), all.end(), std::greater<>());
	printf("%lld\n", std::accumulate(all.begin(), all.begin() + k, 0));
	return 0;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;
std::vector<int> all;
std::vector<int> size;
std::vector<int> depth;

void dfs(int i, int prev) {
	bool has_child = false;
	for (auto j : hen[i]) if (j != prev) {
		has_child = true;
		depth[j] = depth[i] + 1;
		dfs(j, i);
		size[i] += size[j];
	}
	all.push_back(depth[i] - size[i] + 1);
}

int main() {
	int n = ri();
	int k = ri();
	hen.resize(n);
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	size.resize(n, 1);
	depth.resize(n);
	dfs(0, -1);
	std::sort(all.begin(), all.end(), std::greater<>());
	printf("%lld\n", std::accumulate(all.begin(), all.begin() + k, 0LL));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v[200005];
int a[200005];
int sub[200005];
vector<int> dep[400005];
bool vis[200005];
int maxn=-1;
void dfs(int u, int fa, int cnt){
    a[u]=cnt;
    maxn=max(maxn,cnt);
    for (int i=0;i<v[u].size();i++) {
        int w=v[u][i];
        if (w!=fa) dfs(w,u,cnt+1);
        sub[u]+=sub[i];
    }
    sub[u]+=v[u].size()-1;
}
int main()
{
    int x, y;
    scanf("%d%d",&n,&k);
    for (int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,0,0);
    for (int i=1;i<=n;i++)
        dep[a[i]+n].push_back(i);
    int cnt=0;
    int j=maxn+n;
    int ans=0;
    while (cnt<k){
        for (int i=0;i<dep[j].size()&&cnt<k;i++){
            int w=dep[j][i];
            if (vis[w]) ans+=j-n,cnt++;
            else{
                dep[j-sub[w]].push_back(w);
                vis[w]=true;
            }
        }
        j--;
    }
    printf("%d",ans);
    return 0;
}
/*
8 5
1 2
1 3
2 4
2 5
4 7
4 8
3 6
*/


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n, k;
vector<int> v[200005];
int a[200005];
int sub[200005];
vector<int> dep[400005];
bool vis[200005];
int maxn=-1;
void dfs(int u, int fa, int cnt){
    a[u]=cnt;
    maxn=max(maxn,cnt);
    for (int i=0;i<v[u].size();i++) {
        int w=v[u][i];
        if (w!=fa){
            dfs(w,u,cnt+1);
            sub[u]+=sub[w];
        }
    }
    sub[u]+=v[u].size()-1;
    if (u==1) sub[u]++;
}
int main()
{
    int x, y;
    scanf("%d%d",&n,&k);
    for (int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,0,0);
    for (int i=1;i<=n;i++)
        dep[a[i]+n].push_back(i);
    int cnt=0;
    int j=maxn+n;
    int ans=0;
    while (cnt<k){
        for (int i=0;i<dep[j].size()&&cnt<k;i++){
            int w=dep[j][i];
//            cout << w << " " << j << endl;
            if (vis[w]) ans+=j-n,cnt++;
            else{
                dep[j-sub[w]].push_back(w);
                vis[w]=true;
            }
        }
        j--;
    }
    printf("%d",ans);
    return 0;
}
/*
6 4
1 2
2 3
3 4
4 5
5 6
*/


#include<bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v[200005];
int a[200005];
vector<int> dep[400005];
bool vis[200005];
int maxn=-1;
void dfs(int u, int fa, int cnt){
    a[u]=cnt;
    maxn=max(maxn,cnt);
    for (int i=0;i<v[u].size();i++) {
        int w=v[u][i];
        if (w!=fa) dfs(w,u,cnt+1);
    }
}
int main()
{
    int x, y;
    scanf("%d%d",&n,&k);
    for (int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,0,0);
    for (int i=1;i<=n;i++)
        dep[a[i]+n].push_back(i);
    int cnt=0;
    int j=maxn+n;
    int ans=0;
    while (cnt<k){
        for (int i=0;i<dep[j].size()&&cnt<k;i++){
            int w=dep[j][i];
            if (vis[w]) ans+=j-n,cnt++;
            else{
                dep[j-v[w].size()+1].push_back(w);
                vis[w]=true;
            }
        }
        j--;
    }
    printf("%d",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
int n, k;
vector<int> v[200005];
int a[200005];
int sub[200005];
vector<int> dep[400005];
bool vis[200005];
int maxn=-1;
void dfs(int u, int fa, int cnt){
    a[u]=cnt;
    maxn=max(maxn,cnt);
    for (int i=0;i<v[u].size();i++) {
        int w=v[u][i];
        if (w!=fa){
            dfs(w,u,cnt+1);
            sub[u]+=sub[w];
        }
    }
    sub[u]+=v[u].size()-1;
    if (u==1) sub[u]++;
}
int main()
{
    int x, y;
    scanf("%d%d",&n,&k);
    for (int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,0,0);
    for (int i=1;i<=n;i++)
        dep[a[i]+n].push_back(i);
    int cnt=0;
    ll j=(ll)(maxn+n);
    ll ans=0;
    while (cnt<k){
        for (int i=0;i<dep[j].size()&&cnt<k;i++){
            int w=dep[j][i];
//            cout << w << " " << j << endl;
            if (vis[w]) ans+=j-n,cnt++;
            else{
                dep[j-sub[w]].push_back(w);
                vis[w]=true;
            }
        }
        j--;
    }
    printf("%lld",ans);
    return 0;
}
/*
6 4
1 2
2 3
3 4
4 5
5 6
*/


#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
#define pb push_back

using namespace  std;

const int N = 2e5+5;
vector<int> g[N];
int chdnum[N],dep[N];

void dfs(int x,int f){
    dep[x] = dep[f]+1;
    chdnum[x] = 1;
    for(int v:g[x]){
        if(v==f) continue;
        //++chdnum[x];
        dfs(v,x);
        chdnum[x]+=chdnum[v];
    }
}
int d[N],vis[N];
bool cmp(int a,int b){
    if(chdnum[a]<chdnum[b]){
        return true;
    }else if(chdnum[a]==chdnum[b]){
        if(dep[a]>dep[b]){
            return true;
        }else{
            return false;
        }
    }
    else if(chdnum[a]>chdnum[b]){
        return false;
    }
}
ll ans = 0;
void dfs1(int x,int f){
    //int fg = 0;
    //ll ans = 0;
    for(int v:g[x]){
        if(v==f) continue;
        if(!vis[v]){
            //fg = 1;
            dfs1(v,x);
        }
        else{
            ans += dep[x]*chdnum[v];
        }
    }

}
int main(){
    ios::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    rep(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);g[v].push_back(u);
    }
    //dep[1] = 1;
    dfs(1,0);
    rep(i,1,n){
        d[i] = i;
    }
    sort(d+1,d+1+n,cmp);
    rep(i,1,k){
        vis[d[i]] = 1;
        //cout<<d[i]<<' ';
    }
    //cout<<endl;
    dfs1(1,0);
    cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
#define pb push_back

using namespace  std;

const int N = 2e5+5;
vector<int> g[N];
int chdnum[N],dep[N];

void dfs(int x,int f){
    dep[x] = dep[f]+1;
    for(int v:g[x]){
        if(v==f) continue;
        ++chdnum[x];
        dfs(v,x);
        chdnum[x]+=chdnum[v];
    }
}
int d[N],vis[N];
bool cmp(int a,int b){
    if(chdnum[a]<chdnum[b]){
        return true;
    }else if(chdnum[a]==chdnum[b]){
        if(dep[a]>dep[b]){
            return true;
        }else{
            return false;
        }
    }
    else if(chdnum[a]>chdnum[b]){
        return false;
    }
}
ll ans = 0;
void dfs1(int x,int f){
    int fg = 0;
    //ll ans = 0;
    for(int v:g[x]){
        if(v==f) continue;
        if(!vis[v]){
            //fg = 1;
            dfs1(v,x);
        }
        else{
            ans += dep[x]*(chdnum[v]+1);
        }
    }

}
int main(){
    ios::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    rep(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);g[v].push_back(u);
    }
    //dep[1] = 1;
    dfs(1,0);
    rep(i,1,n){
        d[i] = i;
    }
    sort(d+1,d+1+n,cmp);
    rep(i,1,k){
        vis[d[i]] = 1;
        cout<<d[i]<<' ';
    }
    cout<<endl;
    dfs1(1,0);
    cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
#define pb push_back

using namespace  std;

const int N = 2e5+5;
vector<int> g[N];
int chdnum[N],dep[N];

void dfs(int x,int f){
    dep[x] = dep[f]+1;
    for(int v:g[x]){
        if(v==f) continue;
        ++chdnum[x];
        dfs(v,x);
        chdnum[x]+=chdnum[v];
    }
}
int d[N],vis[N];
bool cmp(int a,int b){
    if(chdnum[a]<chdnum[b]){
        return true;
    }else if(chdnum[a]==chdnum[b]){
        if(dep[a]>dep[b]){
            return true;
        }else{
            return false;
        }
    }
    else if(chdnum[a]>chdnum[b]){
        return false;
    }
}
ll ans = 0;
void dfs1(int x,int f){
    int fg = 0;
    //ll ans = 0;
    for(int v:g[x]){
        if(v==f) continue;
        if(!vis[v]){
            //fg = 1;
            dfs1(v,x);
        }
        else{
            ans += dep[x]*(chdnum[v]+1);
        }
    }

}
int main(){
    ios::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    rep(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);g[v].push_back(u);
    }
    //dep[1] = 1;
    dfs(1,0);
    rep(i,1,n){
        d[i] = i;
    }
    sort(d+1,d+1+n,cmp);
    rep(i,1,k){
        vis[d[i]] = 1;
        //cout<<d[i]<<' ';
    }
    //cout<<endl;
    dfs1(1,0);
    cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
#define pb push_back

using namespace  std;

const int N = 2e5+5;
vector<int> g[N];
int chdnum[N],dep[N];

void dfs(int x,int f){
    dep[x] = dep[f]+1;
    chdnum[x] = 1;
    for(int v:g[x]){
        if(v==f) continue;
        //++chdnum[x];
        dfs(v,x);
        chdnum[x]+=chdnum[v];
    }
}
int d[N],vis[N];

// bool cmp(int a,int b){
//     if(chdnum[a]<chdnum[b]){
//         return true;
//     }else if(chdnum[a]==chdnum[b]){
//         if(dep[a]>dep[b]){
//             return true;
//         }else{
//             return false;
//         }
//     }
//     else if(chdnum[a]>chdnum[b]){
//         return false;
//     }
// }
ll ans = 0;
void dfs1(int x,int f){

    for(int v:g[x]){
        if(v==f) continue;
        if(!vis[v]){
            //fg = 1;
            dfs1(v,x);
        }
        else{
            ans += dep[x]*chdnum[v];
        }
    }

}
int main(){
    ios::sync_with_stdio(0);
    int n,k;cin>>n>>k;
    rep(i,1,n-1){
        int u,v;cin>>u>>v;
        g[u].push_back(v);g[v].push_back(u);
    }
    //dep[1] = 1;
    dfs(1,0);
    // rep(i,1,n){
    //     d[i] = i;
    // }
    rep(i,1,n){
        d[i] = dep[i] - chdnum[i];
    }
    sort(d+1,d+1+n,greater<int>());
    // rep(i,1,k){
    //     vis[d[i]] = 1;
    //     //cout<<d[i]<<' ';
    // }
    //cout<<endl;
    //dfs1(1,0);
    rep(i,1,k){
        ans += d[i];
    }
    cout<<ans;
}


#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#define ll long long int
#define e() cout << endl;
#define MA INT_MAX
#define MI INT_MIN
#define MOD 1000000007;
#define ppi pair <int,int>
#define scn(n) scanf("%d",&n)
#define vvi(n,m,x) vector <vector <int> > v(n,vector <int> (m,x));
#define cp(x,y) cout << "Case : " << x << " " << y << endl;
using namespace std;
map <int,set <int> > mp;
map <int,int> p,col,dist;
std::vector<ppi> v;
int h;
bool comp(pair <int,int> x,pair <int,int> y)
{
	if(x.first == y.first)
		return dist[x.second] >= dist[y.second];
	return x.first < y.first;
}
int dfs(int x,int parent,int d)
{
	int cnt = 1;
	dist[x] = d;
	p[x] = parent;
	for(int y : mp[x])
		if(y != parent)
			cnt += dfs(y,x,d + 1);
	//cout << "inserting : " << x << " " << cnt << endl;
	v.push_back(make_pair(cnt,x));
	return cnt;
}

int main()
{
	int n,k;
	cin >> n >> k;
	for(int i = 0;i < n - 1;i++)
	{
		int x,y;
		cin >> x >> y;
		mp[x].insert(y);
		mp[y].insert(x);
	}
	int x = dfs(1,-1,1);

	sort(v.begin(), v.end(),comp);
	for(int i = 0;i < k;i++)
	{
	//	cout << "colored : " << v[i].second << endl;
		col[v[i].second] = 1;
	}

	ll ans = 0;
	for(int i = 0;i < k;i++)
	{
	//	cout << "processing : " << i << endl;
		int x = v[i].second,len = 0;
		while(p[x] != -1)
		{
			x = p[x];
		//	cout << "path : " << x << " " << col[x] << endl;
			len += (col[x] == 0);
		}
		//cout << "total convoy len : " << len << endl;
		//e();
		ans += len;
	}
	cout << ans << endl;
}


#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#define ll long long int
#define e() cout << endl;
#define MA INT_MAX
#define MI INT_MIN
#define MOD 1000000007;
#define ppi pair <int,int>
#define scn(n) scanf("%d",&n)
#define vvi(n,m,x) vector <vector <int> > v(n,vector <int> (m,x));
#define cp(x,y) cout << "Case : " << x << " " << y << endl;
using namespace std;
map <ll,set <ll> > mp;
std::vector<ll> v;
int dfs(ll x,ll parent,ll d)
{
	ll cnt = 1;
	for(ll y : mp[x])
		if(y != parent)
			cnt += dfs(y,x,d + 1);

	v[x] = d - cnt;
	return cnt;
}
int main()
{
	ll n,k,ans = 0;
	cin >> n >> k;
	v = std::vector<ll> (n + 1,0);
	v[0] = MA;
	for(ll i = 1;i < n;i++)
	{
		int x,y;
		cin >> x >> y;
		mp[x].insert(y);
		mp[y].insert(x);
	}

	dfs(1,0,1);
	sort(v.begin() + 1, v.begin() + n + 1);
	for(ll i = n;i > n - k;i--)
		ans += v[i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#define ll long long int
#define e() cout << endl;
#define MA INT_MAX
#define MI INT_MIN
#define MOD 1000000007;
#define ppi pair <int,int>
#define scn(n) scanf("%d",&n)
#define vvi(n,m,x) vector <vector <int> > v(n,vector <int> (m,x));
#define cp(x,y) cout << "Case : " << x << " " << y << endl;
using namespace std;
map <int,set <int> > mp;
std::vector<int> v;
int dfs(int x,int parent,int d)
{
	int cnt = 1;
	for(int y : mp[x])
		if(y != parent)
			cnt += dfs(y,x,d + 1);

	v[x] = d - cnt;
	return cnt;
}
int main()
{
	int n,k,ans = 0;
	cin >> n >> k;
	v = std::vector<int> (n + 1,0);
	v[0] = MA;
	for(int i = 1;i < n;i++)
	{
		int x,y;
		cin >> x >> y;
		mp[x].insert(y);
		mp[y].insert(x);
	}

	dfs(1,0,1);
	sort(v.begin() + 1, v.begin() + n + 1);
	for(int i = n;i > n - k;i--)
		ans += v[i];
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define maxn 200005
std::vector<int>conj[maxn];
int n,k,u,v,depth[maxn]={0},size[maxn]={0},det[maxn];
long long ans=0;
int cmp(int a,int b){return a>b;}
int dfs(int u,int f){depth[u]=depth[f]+1;size[u]=1;
	for (int i=0;i<conj[u].size();++i){
		if ((v=conj[u][i])==f)continue;
		size[u]+=dfs(v,u);
	}det[u]=size[u]-depth[u];return size[u];
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;++i){
		scanf("%d%d",&u,&v);conj[u].push_back(v);conj[v].push_back(u);
	}dfs(1,0);
	std::nth_element(det+1,det+n-k,det+n+1,cmp);
	for (int i=1;i<=n-k;++i)ans+=det[i];std::cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
vector<int>conj[maxn];
int n,k,u,v,depth[maxn]={0},size[maxn]={0},det[maxn];
long long ans=0;
vector<int>pob;
int cmp(int a,int b){return a>b;}
int dfs(int u,int f){
    depth[u]=depth[f]+1;
    size[u]=1;

	for (int i=0;i<conj[u].size();++i){
		if ((v=conj[u][i])==f)continue;
		size[u]+=dfs(v,u);
	}
	pob.push_back(size[u]-depth[u]);
	return size[u];
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;++i){
		scanf("%d%d",&u,&v);conj[u].push_back(v);conj[v].push_back(u);
	}dfs(1,0);
	sort(pob.begin(),pob.end(),greater<int>());
	for(int i=0;i<k;i++)ans+=pob[i];
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define maxn 200005
std::vector<int>conj[maxn];
int n,k,u,v,depth[maxn]={0},size[maxn]={0},det[maxn];
long long ans=0;
vector<int>pob;
int cmp(int a,int b){return a>b;}
int dfs(int u,int f){
    depth[u]=depth[f]+1;
    size[u]=1;

	for (int i=0;i<conj[u].size();++i){
		if ((v=conj[u][i])==f)continue;
		size[u]+=dfs(v,u);
	}
	pob.push_back(size[u]-depth[u]);
	return size[u];
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;++i){
		scanf("%d%d",&u,&v);conj[u].push_back(v);conj[v].push_back(u);
	}dfs(1,0);
	sort(pob.begin(),pob.end(),greater<int>());
	for(int i=0;i<k;i++)ans+=pob[i];
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define Mp make_pair
#define N 200007
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rgt int s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
int head[N],n,m,ver[N<<1],nxt[N<<1],t,f[N];
int dep[N],size[N],vis[N];LL ans;
pair<LL,int>c;
priority_queue<pair<LL,int> >p;
inline void add(rint x,rint y) {
	ver[++t]=y,nxt[t]=head[x],head[x]=t,
	ver[++t]=x,nxt[t]=head[y],head[y]=t;
}
inline void dfs(rint k,rint fa) {
	rint i,to;dep[k]=dep[fa]+1,
	size[k]=1,f[k]=fa;
	for(i=head[k];i;i=nxt[i]) {
		to=ver[i];if(to==fa) continue;
		dfs(to,k),size[k]+=size[to];
	}vis[k]=size[k]-1;
}
int main() {
	rint i,r;n=read(),m=read();
	for(i=1;i<n;i++) add(read(),read());dfs(1,0);
	for(i=1;i<=n;i++) if(!vis[i]) p.push(Mp(dep[i]-1,i));
	for(i=1;i<=m;i++) {
		c=p.top(),p.pop(),r=f[c.second],ans+=c.first;
		--vis[r];
		if(!vis[r]) p.push(Mp((LL)size[r]*(dep[r]-1)-(LL)(size[r]-1)*dep[r],r));
	}printf("%lld",ans);
	return 0;
}


#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define Mp make_pair
#define N 200007
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rgt int s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
int head[N],n,m,ver[N<<1],nxt[N<<1],t,f[N];
int dep[N],size[N],vis[N];LL ans;
pair<LL,int>c;
priority_queue<pair<LL,int> >p;
inline void add(rint x,rint y) {
	ver[++t]=y,nxt[t]=head[x],head[x]=t,
	ver[++t]=x,nxt[t]=head[y],head[y]=t;
}
inline void dfs(rint k,rint fa) {
	rint i,to;dep[k]=dep[fa]+1,
	size[k]=1,f[k]=fa;
	for(i=head[k];i;i=nxt[i]) {
		to=ver[i];if(to==fa) continue;
		dfs(to,k),size[k]+=size[to];
	}vis[k]=size[k]-1;
}
int main() {
	rint i,r;n=read(),m=read();
	for(i=1;i<n;i++) add(read(),read());dfs(1,0);
	for(i=1;i<=n;i++) if(!vis[i]) p.push(Mp(dep[i]-1,i));
	for(i=1;i<=m;i++) {
		c=p.top(),p.pop(),r=f[c.second],ans+=c.first,vis[r]-=size[c.second];
//		printf("vis[%d]=%d c.first=%lld c.second=%d\n",r,vis[r],c.first,c.second);
		if(!vis[r]) p.push(Mp((LL)size[r]*(dep[r]-1)-(LL)(size[r]-1)*dep[r],r));
	}printf("%lld",ans);
	return 0;
}


#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define N 200007
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rgt int s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
struct node{
	int dep,size;
}b[N];
int head[N],n,m,ver[N<<1],nxt[N<<1],t;
LL ans;
inline void add(rint x,rint y) {
	ver[++t]=y,nxt[t]=head[x],head[x]=t,
	ver[++t]=x,nxt[t]=head[y],head[y]=t;
}
inline void dfs(rint k,rint fa) {
	rint i,to;b[k].dep=b[fa].dep+1,b[k].size=1;
	for(i=head[k];i;i=nxt[i]) {
		to=ver[i];if(to==fa) continue;
		dfs(to,k),b[k].size+=b[to].size;
	}
}
inline bool cmp(rgt node a,rgt node b) {
	return (a.dep!=b.dep)?a.dep>b.dep:a.size<b.size;
}
int main() {
	rint i;n=read(),m=read();
	for(i=1;i<n;i++) add(read(),read());
	dfs(1,0),sort(b+1,b+n+1,cmp);
	for(i=1;i<=m;i++)
		ans+=(LL)b[i].size*(b[i].dep-1)-(LL)(b[i].size-1)*b[i].dep;
	printf("%lld",ans);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
	long long to,next;
}edge[400020];
long long cnt,head[200010];
void add(long long a,long long b)
{
	cnt++;edge[cnt].next=head[a];head[a]=cnt;edge[cnt].to=b;
}
bool cmp(long long a,long long b)
{
	return a>b;
}
long long n,k,x,y,ans,v;
long long siz[200010],dp[200010];
void dfs(long long now,long long fa,long long d)
{
	siz[now]=1;dp[now]=d;
	for(long long i=head[now];i;i=edge[i].next)
	{
		v=edge[i].to;
		if(v==fa)
		{
			continue;
		}
		dfs(v,now,d+1);
		siz[now]+=siz[v];
	}
	dp[now]=dp[now]-siz[now];
	dp[now]++;
}
int main()
{
	long long a,b;
	scanf("%lld %lld",&n,&k);
	for(long long i=1;i<n;i++)
	{
		scanf("%lld %lld",&a,&b);
		add(a,b);add(b,a);
	}
	dfs(1,-1,0);
	sort(dp+1,dp+1+n,cmp);
	for(long long i=1;i<=k;i++)
	{
		ans+=dp[i];
	}
	printf("%lld",ans);
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
	long long to,next;
}edge[400020];
long long cnt,head[200010];
void add(long long a,long long b)
{
	cnt++;edge[cnt].next=head[a];head[a]=cnt;edge[cnt].to=b;
}
bool cmp(long long a,long long b)
{
	return a>b;
}
long long n,k,x,y,ans,v;
long long dis[200010],siz[200010],dp[200010];
void dfs(long long now,long long fa,long long d)
{
	siz[now]=1;dis[now]=d;
	for(long long i=head[now];i;i=edge[i].next)
	{
		v=edge[i].to;
		if(v==fa)
		{
			continue;
		}
		dfs(v,now,d+1);
		siz[now]+=siz[v];
	}
	dp[now]=dis[now]-siz[now];
	dp[now]=dp[now]+1;
}
int main()
{
	long long a,b;
	scanf("%lld %lld",&n,&k);
	for(long long i=1;i<n;i++)
	{
		scanf("%lld %lld",&a,&b);
		add(a,b);add(b,a);
	}
	dfs(1,0,0);
	sort(dp+1,dp+1+n,cmp);
	for(long long i=1;i<=k;i++)
	{
		ans+=dp[i];
	}
	printf("%lld",ans);
}


#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int t;int n,num[1000001];
int maxn=-999,maxc=-9999;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);

		for(int i=1;i<=n;i++)
		{
			scanf("%d",&num[i]);
		}
		maxn=num[1],maxc=0;
		for(int i=1;i<=n;i++)
		{
			maxn=max(maxn,num[i]);
			maxc=max(maxc,maxn-num[i]);
		}

		int ans=0,sum=0,p=1;
		while(sum<maxc)
		{
			ans++;
			sum+=p;p=p*2;
		}
		printf("%d\n",ans);
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 2e5 + 5;
int n, k, f[N], s[N];
vector<int>G[N];

void dfs(int x, int fa, int d) {
	f[x] = d;
	s[x] = 1;
	for (int c : G[x]) {
		if (c == fa) continue;
		dfs(c, x, d + 1);
		s[x] += s[c];//f[x] -= s[c];
	}
	f[x] -= s[x] - 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1, 0);
	sort(f + 1, f + 1 + n, greater<int>());
	int res = 0;
	for (int i = 1; i <= k; i++) {
		res += f[i];
	}
	cout << res << '\n';
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
	int to,next;
}edge[400020];
int cnt,head[200010];
void add(int a,int b)
{
	cnt++;edge[cnt].next=head[a];head[a]=cnt;edge[cnt].to=b;
}
bool cmp(int a,int b)
{
	return a>b;
}
int n,k;int x,y;int ans;int v;
int dis[200010],siz[200010],dp[200010];
void dfs(int now,int fa,int d)
{
	siz[now]=1;dis[now]=d;
	for(int i=head[now];i;i=edge[i].next)
	{
		v=edge[i].to;
		if(v==fa)
		{
			continue;
		}
		dfs(v,now,d+1);
		siz[now]+=siz[v];
	}
	dp[now]=dis[now]-siz[now];
	dp[now]=dp[now]+1;
}
int main()
{
	int a,b;
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		add(a,b);add(b,a);
	}
	dfs(1,0,0);
	sort(dp+1,dp+1+n,cmp);
	for(int i=1;i<=k;i++)
	{
		ans+=dp[i];
	}
	printf("%d",ans);
}


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int>P;
    const double eps = 1e-8;
    const int NINF = 0xc0c0c0c0;
    const int INF  = 0x3f3f3f3f;
    const ll  mod  = 1e9 + 7;
    const ll  maxn = 1e6 + 5;
    const int N = 2e5 + 5;

    ll n,k,f[N],s[N];
    vector<int>G[N];

    void dfs(int x,int fa,ll d){
    	f[x]=d;
    	s[x]=1;
    	for(int c:G[x]){
    		if(c==fa) continue;
    		dfs(c,x,d+1);
    		s[x]+=s[c];
    	}
f[x]-=s[x];f[x]++;
    }

    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cin>>n>>k;
    	for(int i=1;i<n;i++){
    		int u,v;cin>>u>>v;
    		G[u].push_back(v);
    		G[v].push_back(u);
    	}
    	dfs(1,-1,0);
    	sort(f+1,f+1+n,greater<ll>());
    	ll res=0;
    	for(int i=1;i<=k;i++){
    		res+=f[i];
    	}
    	cout<<res<<'\n';
    	return 0;
    }


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int, int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const int  mod = 1e9 + 7;
const int  maxn = 1e6 + 5;
const int N = 2e5 + 5;

int n, k, f[N], s[N];
vector<int>G[N];

void dfs(int x, int fa, int d) {
	f[x] = d;
	s[x] = 1;
	for (int c : G[x]) {
		if (c == fa) continue;
		dfs(c, x, d + 1);
		s[x] += s[c];
		f[x] -= s[c];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1, 0);
	sort(f + 1, f + 1 + n, greater<int>());
	int res = 0;
	for (int i = 1; i <= k; i++) {
		res += f[i];
	}
	cout << res << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	map<int, int> ex;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex[a[i]]++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j)
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex[a[i]]--;
			fb.push_back(a[j]);
			ex[a[j]]--;

			while(ex[fb[fb.size()-1]+fb[fb.size()-2]]>0 )
			{
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				if (abs(k) > int(1e9)) break;
				ex[k]--;
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex[z]++;
		}
	}
	cout << ans;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	map<int, int> ex;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex[a[i]]++;
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j && (a[i] != 0 || a[j] != 0))
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex[a[i]]--;
			fb.push_back(a[j]);
			ex[a[j]]--;

			while(ex[fb[fb.size()-1]+fb[fb.size()-2]]>0 )
			{
			//	cout << '*';
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				if (abs(k) > int(1e9)) break;
				ex[k]--;
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex[z]++;
		}
	}
	cout << max(ans,k);
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	multiset<int> ex;
	map<int, int> sp;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		sp[a[i]]++;
		if (sp[a[i]] <= 2)
		ex.insert(a[i]);
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j && (a[i] != 0 || a[j] != 0))
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex.erase(ex.find(a[i]));
			fb.push_back(a[j]);
			ex.erase(ex.find(a[j]));

			while(ex.count(fb[fb.size()-1]+fb[fb.size()-2]) )
			{
			//	cout << '*';
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				if (abs(k) > int(1e9)) break;
				ex.erase(ex.find(k));
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex.insert(z);
		}
	}
	cout << max(ans,k);
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	set<int> ex;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex.insert(a[i]);
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = i+1; j < n; j++)
	{
		vector<ll> fb;
		fb.push_back(a[i]);
		fb.push_back(a[j]);
		for(int z = 0; z < 200; z++)
		{
			fb.push_back(fb[fb.size()-1]+fb[fb.size()-2]);
			if (fb[fb.size()-1]>int(1e9))break;
		}

		for(int z = 0; z < 200 ; z++)
		{
		//	cout << z << ' ' << fb[z] << '\n';
			if (!ex.count(fb[z]))
			{
				ans = max(ans, z);
				break;
			}
		}
	}
	cout << ans;
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	multiset<int> ex;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex.insert(a[i]);
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j)
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex.erase(ex.find(a[i]));
			fb.push_back(a[j]);
			ex.erase(ex.find(a[j]));

			while(ex.count(fb[fb.size()-1]+fb[fb.size()-2]) )
			{
			//	cout << '*';
				ex.erase(fb[fb.size()-1]+fb[fb.size()-2]);
				fb.push_back(fb[fb.size()-1]+fb[fb.size()-2]);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex.insert(z);
		}
	}
	cout << max(ans,k);
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	multiset<int> ex;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex.insert(a[i]);
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j)
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex.erase(ex.find(a[i]));
			fb.push_back(a[j]);
			ex.erase(ex.find(a[j]));

			while(ex.count(fb[fb.size()-1]+fb[fb.size()-2]) )
			{
			//	cout << '*';
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				ex.erase(k);
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex.insert(z);
		}
	}
	cout << max(ans,k);
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	multiset<int> ex;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex.insert(a[i]);
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j && (a[i] != 0 || a[j] != 0))
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex.erase(ex.find(a[i]));
			fb.push_back(a[j]);
			ex.erase(ex.find(a[j]));

			while(ex.count(fb[fb.size()-1]+fb[fb.size()-2]) )
			{
			//	cout << '*';
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				ex.erase(ex.find(k));
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex.insert(z);
		}
	}
	cout << max(ans,k);
}


#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

const int N = int(2e5+5);
const int MOD = int(1e9+7);

typedef long long ll;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> a(n);
	multiset<int> ex;

	int k = 0;

	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		ex.insert(a[i]);
		if (a[i]==0) k++;
	}

	int ans = 0;

	for(int i = 0; i < n; i++)
	for(int j = 0; j < n; j++)
	{
		if (i!=j && (a[i] != 0 || a[j] != 0))
		{
			vector<ll> fb;
			fb.push_back(a[i]);
			ex.erase(ex.find(a[i]));
			fb.push_back(a[j]);
			ex.erase(ex.find(a[j]));

			while(ex.count(fb[fb.size()-1]+fb[fb.size()-2]) )
			{
			//	cout << '*';
				int k = fb[fb.size()-1]+fb[fb.size()-2];
				ex.erase(k);
				fb.push_back(k);
			}

			ans = max(ans,int(fb.size()) );

			for(auto z:fb) ex.insert(z);
		}
	}
	cout << max(ans,k);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	if(aray[0] == 0 && aray[n-1] == 0)
	{
		cout<<n<<"\n";
		return 0;
	}
	int ans = 0;
	map<pair<int, int>, int> done;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			if(done.count(make_pair(aray[i], aray[j])))
				continue;
			done[make_pair(aray[i], aray[j])] = 1;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2, curr = aray[j], num = aray[i] + aray[j];
			while(1)
			{
				if(m.count(num) && m[num])
				{
					count++;
					m[num]--;
					v.push_back(num);
					int temp = num;
					num += curr;
					curr = temp;
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	int ans = 0;
	map<pair<int ,int>, int > done;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(done.count(make_pair(aray[i], aray[j])))
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num))
				{
					done[make_pair(curr1, curr2)] = 1;
					count++;
					curr1 = curr2;
					curr2 = curr1+curr2;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	if(aray[0] == 0 && aray[n-1] == 0)
	{
		cout<<n<<"\n";
		return 0;
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num) && m[num])
				{
					count++;
					curr1 = curr2;
					curr2 = num;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num))
				{
					count++;
					curr1 = curr2;
					curr2 = curr1+curr2;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	if(aray[0] == 0 && aray[n-1] == 0)
	{
		cout<<n<<"\n";
		return 0;
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			if(done.count(make_pair(aray[i], aray[j])))
				continue;
			done[make_pair(aray[i], aray[j])] = 1;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2, curr = aray[j], num = aray[i] + aray[j];
			while(1)
			{
				if(m.count(num) && m[num])
				{
					count++;
					m[num]--;
					v.push_back(num);
					int temp = num;
					num += curr;
					curr = temp;
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	int ans = 0;
	map<pair<int ,int>, int > done;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			if(done.count(make_pair(aray[i], aray[j])))
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num))
				{
					done[make_pair(curr1, curr2)] = 1;
					count++;
					curr1 = curr2;
					curr2 = curr1+curr2;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	if(aray[0] == 0 && aray[n-1] == 0)
	{
		cout<<n<<"\n";
		return 0;
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num))
				{
					count++;
					curr1 = curr2;
					curr2 = curr1+curr2;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int aray[n];
	map<int, int> m;
	for(int i=0;i<n;i++)
	{
		cin>>aray[i];
		if(m.count(aray[i]))
			m[aray[i]]++;
		else
			m[aray[i]] = 1;
	}
	sort(aray, aray+n);
	if(aray[0] == 0 && aray[n-1] == 0)
	{
		cout<<n<<"\n";
		return 0;
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j == i)
				continue;
			vector<int> v;
			v.push_back(aray[i]);
			m[aray[i]]--;
			v.push_back(aray[j]);
			m[aray[j]]--;
			int count = 2;
			int curr1 = aray[i], curr2 = aray[j];
			while(1)
			{
				int num = curr1+curr2;
				if(m.count(num) && m[num])
				{
					count++;
					curr1 = curr2;
					curr2 = curr1+curr2;
					m[num]--;
					v.push_back(num);
				}
				else
					break;
			}
			ans = max(ans, count);
			for(int i=0;i<v.size();i++)
				m[v[i]]++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

long long n, a, ans;
vector <int> num;
map <int, int> mark;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (mark[a]++)
            continue;
        if (mark[a] < 3)
            num.push_back(a);
    }
    for (int i = 0; i < num.size(); i++){
        for (int j = 0; j < num.size(); j++){
            if (j == i)
                continue;
            long long a1 = num[i], a2 = num[j], cnt = 1;
            while(mark[a2]){
                long long a3 = a1 + a2;
                a1 = a2;
                a2 = a3;
                cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e6 + 10;

int n, a[N], val, val2, cnt, ans, temp;
queue <int> q;
map <pair<int, int>, bool> mark;
unordered_map <int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == i || mark[{i, j}]++)
                continue;
            mp[a[i]]--;
            mp[a[j]]--;
            q.push(a[i]);
            q.push(a[j]);
            val2 = a[j];
            val = a[i] + a[j];
            cnt = 2;
            while (mp[val]) {
                cnt++;
                q.push(val);
                mp[val]--;
                temp = val;
                val += val2;
                val2 = temp;
                if (val > 1000000000 || val < -1000000000)
                    break;
            }
            while (q.size()) {
                mp[q.front()]++;
                q.pop();
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e6 + 10;

long long n, a[N], val, val2, cnt, ans, temp;
queue <int> q;
unordered_map <long long, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == i)
                continue;
            mp[a[i]]--;
            mp[a[j]]--;
            q.push(a[i]);
            q.push(a[j]);
            val2 = a[j];
            val = a[i] + a[j];
            cnt = 2;
            while (mp[val]) {
                cnt++;
                q.push(val);
                mp[val]--;
                temp = val;
                val += val2;
                val2 = temp;
            }
            while (q.size()) {
                mp[q.front()]++;
                q.pop();
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e6 + 10;

long long n, a[N], val, val2, cnt, ans, temp;
unordered_map <long long, int> mp, mp2;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == i)
                continue;
            mp2 = mp;
            mp2[a[i]]--;
            mp2[a[j]]--;
            val2 = a[j];
            val = a[i] + a[j];
            cnt = 2;
            while (mp2[val]) {
                cnt++;
                mp2[val]--;
                temp = val;
                val += val2;
                val2 = temp;
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e6 + 10;

int n, a[N], val, val2, cnt, ans, temp;
queue <int> q;
map <pair<int, int>, bool> mark;
unordered_map <int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == i || mark[{a[i], a[j]}]++)
                continue;
            mp[a[i]]--;
            mp[a[j]]--;
            q.push(a[i]);
            q.push(a[j]);
            val2 = a[j];
            val = a[i] + a[j];
            cnt = 2;
            while (mp[val]) {
                cnt++;
                q.push(val);
                mp[val]--;
                temp = val;
                val += val2;
                val2 = temp;
                if (val > 1000000000 || val < -1000000000)
                    break;
            }
            while (q.size()) {
                mp[q.front()]++;
                q.pop();
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e6 + 10;

int n, a[N], val, val2, cnt, ans, temp;
queue <int> q;
unordered_map <int, int> mp;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ans = mp[0];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j == i || (a[i] == 0 && a[j] == 0))
                continue;
            mp[a[i]]--;
            mp[a[j]]--;
            q.push(a[i]);
            q.push(a[j]);
            val2 = a[j];
            val = a[i] + a[j];
            cnt = 2;
            while (mp[val]) {
                cnt++;
                q.push(val);
                mp[val]--;
                temp = val;
                val += val2;
                val2 = temp;
                if (val > 1000000000 || val < -1000000000)
                    break;
            }
            while (q.size()) {
                mp[q.front()]++;
                q.pop();
            }
            ans = max(cnt, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

long long n, a, ans;
vector <long long> num;
map <long long, int> mark;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        a += 1000000000;
        if (mark[a]++)
            continue;
        if (mark[a] < 3)
            num.push_back(a);
    }
    for (int i = 0; i < num.size(); i++){
        for (int j = 0; j < num.size(); j++){
            if (j == i)
                continue;
            long long a1 = num[i], a2 = num[j], cnt = 1;
            while(mark[a2]){
                long long a3 = a1 + a2 - 1000000000;
                a1 = a2;
                a2 = a3;
                cnt++;
            }
            ans = max(ans, cnt);
        }
    }
    cout << ans << '\n';
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;

            LL f = a[i], s = a[j];

            if (f == 0 && s == 0) {
                mx_len = max(1LL * mx_len, 1LL * have[0]);
                continue;
            }

            map <LL,LL> used;
            used[f]++;
            used[s]++;

            int cur_len = 2;

            while (1) {
                LL need = f + s;
                if (have[need] != 0 && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else break;

            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (used_pair[{a[i], a[j]}]) continue;
            used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];
            if (a[i] == 0 && a[j] == 0) {
                mx_len = max(1LL * mx_len, 1LL * have.count(0LL));
                continue;
            }
            map <LL,LL> used;
            used[a[i]]++;
            used[a[j]]++;
            int cur_len = 2;
            while (1) {
                LL need = f + s;
                if (have[need] != 0 && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else {
                    break;
                }
            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;

            if (used_pair[{a[i], a[j]}]) continue;
            used_pair[{a[i], a[j]}] = 1;

            LL f = a[i], s = a[j];

            if (f == 0 && s == 0) {
                mx_len = max(1LL * mx_len, 1LL * have[0]);
                continue;
            }

            map <LL,LL> used;
            used[f]++;
            used[s]++;

            int cur_len = 2;

            while (1) {
                LL need = f + s;
                if (have[need] != 0 && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else break;

            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (used_pair[{a[i], a[j]}]) continue;
            used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];
            if (a[i] == 0 && a[j] == 0) {
                mx_len = max(1LL * mx_len, 1LL * have.count(0LL));
                continue;
            }
            map <LL,LL> used;
            used[a[i]]++;
            used[a[j]]++;
            int cur_len = 2;
            while (1) {
                LL need = f + s;
                if (used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else {
                    break;
                }
            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (used_pair.count({a[i], a[j]})) continue;
            used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];
            if (a[i] == 0 && a[j] == 0) {
                mx_len = max(1LL * mx_len, 1LL * have.count(0LL));
                continue;
            }
            map <LL,LL> used;
            used[a[i]]++;
            used[a[j]]++;
            int cur_len = 2;
            while (1) {
                LL need = f + s;
                if (need <= 2 * inf && have.count(need) && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else {
                    break;
                }
            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,int> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, int> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (used_pair.count({a[i], a[j]})) continue;

            used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];

            if (a[i] == 0 && a[j] == 0) {
                mx_len = max(1LL * mx_len, 1LL * have[0]);
                continue;
            }
            map <LL,int> used;
            used[a[i]]++;
            used[a[j]]++;
            int cur_len = 2;
            while (1) {
                LL need = f + s;
                if (have.count(need) && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else break;
            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            //if (used_pair[{a[i], a[j]}]) continue;

            //used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];

            if (f == 0 && s == 0) {
                mx_len = max(1LL * mx_len, 1LL * have.count(0LL));
                continue;
            }

            map <LL,LL> used;
            used[f]++;
            used[s]++;

            int cur_len = 2;

            while (1) {
                LL need = f + s;
                if (have[need] != 0 && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else break;

            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
    const char* c = strchr(na + 1, ',');
    cerr.write(na, c - na) << " : " << arg1 << " , ";
    __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

void solve() {
    int n;
    cin >> n;
    map <LL,LL> have;
    vector <LL> a (n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        have[a[i]]++;
    }

    int mx_len = 0;
    map <pair <LL,LL>, LL> used_pair;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (used_pair[{a[i], a[j]}]) continue;

            used_pair[{a[i], a[j]}] = 1;
            LL f = a[i], s = a[j];

            if (f == 0 && s == 0) {
                mx_len = max(1LL * mx_len, 1LL * have.count(0LL));
                continue;
            }

            map <LL,LL> used;
            used[f]++;
            used[s]++;

            int cur_len = 2;

            while (1) {
                LL need = f + s;
                if (have[need] != 0 && used[need] < have[need]) {
                    used[need]++;
                    f = s;
                    s = need;
                    cur_len++;
                }
                else break;

            }
            mx_len = max(mx_len, cur_len);
        }
    }
    cout << mx_len << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    for (int tc = 1; tc <= t; tc++) solve();
    return 0;
}