import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static class Node implements Comparable<Node>{
        int cnt, dist;
        Node(){
            this.cnt = 0;
            this.dist = 0;
        }

        @Override
        public int compareTo(Node n){
            return (this.dist-this.cnt)-(n.dist-n.cnt) ;
        }

    }

    public static int dfs(int x){
        int count = 0;
        check[x] = true;
        for(int y: a[x]){
            if(check[y] == false){
                nodes[y].dist = nodes[x].dist+1;
                count += dfs(y);
            }
        }
        nodes[x].cnt = count;
        return count+1;
    }

    public static final Scanner scanner = new Scanner(System.in);
    public static ArrayList<Integer>[] a;
    public static Node[] nodes;
    public static boolean[] check;

    public static void main(String[] args){
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        nodes = new Node[n+1];
        a = new ArrayList[n+1];
        check = new boolean[n+1];

        for(int i = 1 ; i <= n ; i++){
            a[i] = new ArrayList<>();
            nodes[i] = new Node();
        }

        for(int i = 1 ; i <= n-1 ; i++){
            int from = scanner.nextInt();
            int to = scanner.nextInt();

            a[from].add(to);
            a[to].add(from);
        }

        dfs(1);

        Arrays.sort(nodes,1,n+1);

        long ans = 0;
        for(int i = n ; i > n-k ; i--){
            ans += nodes[i].dist-nodes[i].cnt;
        }
        System.out.println(ans);

    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static class Node implements Comparable<Node>{
        int index;
        int dist = 0;
        int cnt = 0;

        public Node(int index){
            this.index = index;
        }

        @Override
        public int compareTo(Node n){
            if(this.dist == n.dist) return n.cnt-this.cnt;
            return this.dist-n.dist;
        }
    }

    public static final Scanner scanner = new Scanner(System.in);
    public static boolean[] check;
    public static Node[] d;
    public static int[] c;
    public static ArrayList<Integer>[] a;

    public static int dfs(int x, int dist){
        if(check[x]) return 0;
        check[x] = true;
        // d[x] = dist;
        d[x].dist = dist;
        dist += 1;
        int count = 0;
        for(int y : a[x]){
            if(check[y] == false) count += dfs(y, dist);
        }
        d[x].cnt = count;
        return count+1;
    }

    public static void main(String[] args){
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        a = (ArrayList<Integer>[]) new ArrayList[n+1];
        d = new Node[n+1];
        c = new int[n+1];
        check = new boolean[n+1];
        for(int i = 1 ; i <= n ; i++){
            a[i] = new ArrayList<>();
            d[i] = new Node(i);
        }

        for(int i = 1 ; i <= n-1 ; i++){
            int from = scanner.nextInt();
            int to = scanner.nextInt();
            a[from].add(to);
            a[to].add(from);
            c[from] += 1;
        }

        dfs(1,0);

        int ans = 0;
        // Arrays.sort(d);
        Arrays.sort(d,1,n);

        for(int i = n ; i > n-k ; i--){
            ans += d[i].dist-d[i].cnt;
        }

        System.out.println(ans);

    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Node implements Comparable<Node>{
    int index;
    int dist = 0;
    int cnt = 0;

    public Node(int index){
        this.index = index;
    }

    @Override
    public int compareTo(Node n){
        if(this.dist == n.dist) return n.cnt-this.cnt;
        return this.dist-n.dist;
    }
}

public class Main {
    public static final Scanner scanner = new Scanner(System.in);
    public static boolean[] check;
    public static Node[] d;
    public static int[] c;
    public static ArrayList<Integer>[] a;

    public static int dfs(int x, int dist){
        if(check[x]) return 0;
        check[x] = true;
        // d[x] = dist;
        d[x].dist = dist;
        dist += 1;
        int count = 0;
        for(int y : a[x]){
            if(check[y] == false) count += dfs(y, dist);
        }
        d[x].cnt = count;
        return count+1;
    }

    public static void main(String[] args){
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        a = (ArrayList<Integer>[]) new ArrayList[n+1];
        d = new Node[n+1];
        c = new int[n+1];
        check = new boolean[n+1];
        for(int i = 1 ; i <= n ; i++){
            a[i] = new ArrayList<>();
            d[i] = new Node(i);
        }

        for(int i = 1 ; i <= n-1 ; i++){
            int from = scanner.nextInt();
            int to = scanner.nextInt();
            a[from].add(to);
            a[to].add(from);
            c[from] += 1;
        }

        dfs(1,0);

        int ans = 0;
        // Arrays.sort(d);
        Arrays.sort(d,1,n);

        for(int i = n ; i > n-k ; i--){
            ans += d[i].dist-d[i].cnt;
        }

        System.out.println(ans);

    }
}


import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    static ArrayList<Integer>[] adj;
    static int[] depth,sub;
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        StringBuilder sb=new StringBuilder();
        int n=sc.nextInt(),k=sc.nextInt();
        adj=new ArrayList[n];
        for(int i=0;i<n;i++)adj[i]=new ArrayList<>();
        depth=new int[n];
        sub=new int[n];
        for(int i=0;i<n-1;i++){
            int u=sc.nextInt()-1,v=sc.nextInt()-1;
            adj[u].add(v);
            adj[v].add(u);
        }
        dfs(0,-1);
        Integer[] sum=new Integer[n];
        for(int i=0;i<n;i++){
            sum[i]=depth[i]-sub[i];
        }
        Arrays.sort(sum);
        long ans=0;
        for(int i=0;i<k;i++)ans+=sum[n-1-i];
        System.out.println(ans);
    }
    static int dfs(int curr,int par){
        if(par==-1)depth[curr]=1;
        else depth[curr]=depth[par]+1;
        sub[curr]=1;
        for(int node:adj[curr]){
            if(node!=par){
                sub[curr]+=dfs(node,curr);
            }
        }
        return sub[curr];
    }
}
class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next()); }
    long nextLong() { return Long.parseLong(next()); }
    double nextDouble() { return Double.parseDouble(next()); }
    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static class Node implements Comparable<Node>{
        int cnt, dist;
        Node(){
            this.cnt = 0;
            this.dist = 0;
        }

        @Override
        public int compareTo(Node n){
            return (this.dist-this.cnt)-(n.dist-n.cnt) ;
        }

    }

    public static int dfs(int x){
        int count = 0;
        check[x] = true;
        for(int y: a[x]){
            if(check[y] == false){
                nodes[y].dist = nodes[x].dist+1;
                count += dfs(y);
            }
        }
        nodes[x].cnt = count;
        return count+1;
    }

    public static final Scanner scanner = new Scanner(System.in);
    public static ArrayList<Integer>[] a;
    public static Node[] nodes;
    public static boolean[] check;

    public static void main(String[] args){
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        nodes = new Node[n+1];
        a = new ArrayList[n+1];
        check = new boolean[n+1];

        for(int i = 1 ; i <= n ; i++){
            a[i] = new ArrayList<>();
            nodes[i] = new Node();
        }

        for(int i = 1 ; i <= n-1 ; i++){
            int from = scanner.nextInt();
            int to = scanner.nextInt();

            a[from].add(to);
            a[to].add(from);
        }

        dfs(1);

        Arrays.sort(nodes,1,n+1);

        int ans = 0;
        for(int i = n ; i > n-k ; i--){
            ans += nodes[i].dist-nodes[i].cnt;
        }
        System.out.println(ans);

    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static class Node implements Comparable<Node>{
        int cnt, dist;
        Node(){
            this.cnt = 0;
            this.dist = 0;
        }

        @Override
        public int compareTo(Node n){
            return this.dist-this.cnt - n.dist-n.cnt;
        }

    }

    public static int dfs(int x){
        int count = 0;
        check[x] = true;
        for(int y: a[x]){
            if(check[y] == false){
                nodes[y].dist = nodes[x].dist+1;
                count += dfs(y);
            }
        }
        nodes[x].cnt = count;
        return count+1;
    }

    public static final Scanner scanner = new Scanner(System.in);
    public static ArrayList<Integer>[] a;
    public static Node[] nodes;
    public static boolean[] check;

    public static void main(String[] args){
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        nodes = new Node[n+1];
        a = new ArrayList[n+1];
        check = new boolean[n+1];

        for(int i = 1 ; i <= n ; i++){
            a[i] = new ArrayList<>();
            nodes[i] = new Node();
        }

        for(int i = 1 ; i <= n-1 ; i++){
            int from = scanner.nextInt();
            int to = scanner.nextInt();

            a[from].add(to);
            a[to].add(from);
        }

        dfs(1);

        Arrays.sort(nodes,1,n+1);

        int ans = 0;
        for(int i = n ; i > n-k ; i--){
            ans += nodes[i].dist-nodes[i].cnt;
        }
        System.out.println(ans);

    }
}


package com.codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class LinovaAndKingdom {

    private static Integer[] scores;

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String line = br.readLine();
            String[] array = line.split(" ");
            Integer N = Integer.parseInt(array[0]);
            Integer K = Integer.parseInt(array[1]);

            scores = new Integer[N];

            Map<Integer, Node> graph = new HashMap<>();
            for(int i=0; i<N-1; i++) {
                String edge = br.readLine();
                String[] vertices = edge.split(" ");
                Integer v1 = Integer.parseInt(vertices[0]);
                Integer v2 = Integer.parseInt(vertices[1]);

                if(graph.containsKey(v1)) {
                    graph.get(v1).adjNodes.add(v2);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v2);
                    Node node = new Node(v1);
                    node.adjNodes.add(v2);
                    graph.put(v1, node);
                }

                if(graph.containsKey(v2)) {
                    graph.get(v2).adjNodes.add(v1);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v1);
                    Node node = new Node(v2);
                    node.adjNodes.add(v1);
                    graph.put(v2, node);
                }
            }
            dfsDeleteReverseLInk(graph, 1, null);
            System.out.println(getHappiness(graph, K));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void dfsDeleteReverseLInk(Map<Integer, Node> graph, Integer cur, Integer prev) {
        Node node = graph.get(cur);
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            if(prev != null)
                node.adjNodes.remove(prev);

            for(Integer adj : node.adjNodes) {
                dfsDeleteReverseLInk(graph, adj, cur);
            }
        }
    }

    public static Integer getHappiness(Map<Integer, Node> graph, Integer K) {
        dfs(graph, 1, 0);
        Arrays.sort(scores);
        int ctr = 0;
        int total = 0;
        for(int i=scores.length-1; i>=0; i--) {
            ctr++;
            if(ctr > K) {
                break;
            }
            total += scores[i];
        }
        return total;
    }

    public static Integer dfs(Map<Integer, Node> graph, Integer cur, Integer level) {
        Node node = graph.get(cur);
        Integer count = 0;
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            for(Integer adj : node.adjNodes) {
                count = 1 + count + dfs(graph, adj, level+1);
            }
        }
        scores[cur-1] = level - count;
        return count;
    }

}

class Node {
    int value;
    Set<Integer> adjNodes;
    public Node(int value) {
        this.value = value;
        this.adjNodes = new HashSet<>();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class LinovaAndKingdom {

    private static Integer[] scores;

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String line = br.readLine();
            String[] array = line.split(" ");
            Integer N = Integer.parseInt(array[0]);
            Integer K = Integer.parseInt(array[1]);

            scores = new Integer[N];

            Map<Integer, Node> graph = new HashMap<>();
            for(int i=0; i<N-1; i++) {
                String edge = br.readLine();
                String[] vertices = edge.split(" ");
                Integer v1 = Integer.parseInt(vertices[0]);
                Integer v2 = Integer.parseInt(vertices[1]);

                if(graph.containsKey(v1)) {
                    graph.get(v1).adjNodes.add(v2);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v2);
                    Node node = new Node(v1);
                    node.adjNodes.add(v2);
                    graph.put(v1, node);
                }

                if(graph.containsKey(v2)) {
                    graph.get(v2).adjNodes.add(v1);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v1);
                    Node node = new Node(v2);
                    node.adjNodes.add(v1);
                    graph.put(v2, node);
                }
            }
            dfsDeleteReverseLInk(graph, 1, null);
            System.out.println(getHappiness(graph, K));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void dfsDeleteReverseLInk(Map<Integer, Node> graph, Integer cur, Integer prev) {
        Node node = graph.get(cur);
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            if(prev != null)
                node.adjNodes.remove(prev);

            for(Integer adj : node.adjNodes) {
                dfsDeleteReverseLInk(graph, adj, cur);
            }
        }
    }

    public static Integer getHappiness(Map<Integer, Node> graph, Integer K) {
        dfs(graph, 1, 0);
        Arrays.sort(scores);
        int ctr = 0;
        int total = 0;
        for(int i=scores.length-1; i>=0; i--) {
            ctr++;
            if(ctr > K) {
                break;
            }
            total += scores[i];
        }
        return total;
    }

    public static Integer dfs(Map<Integer, Node> graph, Integer cur, Integer level) {
        Node node = graph.get(cur);
        Integer count = 0;
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            for(Integer adj : node.adjNodes) {
                count = 1 + count + dfs(graph, adj, level+1);
            }
        }
        scores[cur-1] = level - count;
        return count;
    }

}

class Node {
    int value;
    Set<Integer> adjNodes;
    public Node(int value) {
        this.value = value;
        this.adjNodes = new HashSet<>();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class LinovaAndKingdom {

    private static Long[] scores;

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String line = br.readLine();
            String[] array = line.split(" ");
            Integer N = Integer.parseInt(array[0]);
            Integer K = Integer.parseInt(array[1]);

            scores = new Long[N];

            Map<Integer, Node> graph = new HashMap<>();
            for(int i=0; i<N-1; i++) {
                String edge = br.readLine();
                String[] vertices = edge.split(" ");
                Integer v1 = Integer.parseInt(vertices[0]);
                Integer v2 = Integer.parseInt(vertices[1]);

                if(graph.containsKey(v1)) {
                    graph.get(v1).adjNodes.add(v2);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v2);
                    Node node = new Node(v1);
                    node.adjNodes.add(v2);
                    graph.put(v1, node);
                }

                if(graph.containsKey(v2)) {
                    graph.get(v2).adjNodes.add(v1);
                } else {
                    HashSet<Integer> adjNodes = new HashSet<>();
                    adjNodes.add(v1);
                    Node node = new Node(v2);
                    node.adjNodes.add(v1);
                    graph.put(v2, node);
                }
            }
            dfsDeleteReverseLInk(graph, 1, null);
            System.out.println(getHappiness(graph, K));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void dfsDeleteReverseLInk(Map<Integer, Node> graph, Integer cur, Integer prev) {
        Node node = graph.get(cur);
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            if(prev != null)
                node.adjNodes.remove(prev);

            for(Integer adj : node.adjNodes) {
                dfsDeleteReverseLInk(graph, adj, cur);
            }
        }
    }

    public static Long getHappiness(Map<Integer, Node> graph, Integer K) {
        dfs(graph, 1, 0);
        Arrays.sort(scores);
        int ctr = 0;
        long total = 0;
        for(int i=scores.length-1; i>=0; i--) {
            ctr++;
            if(ctr > K) {
                break;
            }
            total += scores[i];
        }
        return total;
    }

    public static long dfs(Map<Integer, Node> graph, Integer cur, Integer level) {
        Node node = graph.get(cur);
        long count = 0;
        if(node.adjNodes != null && node.adjNodes.size() > 0) {
            for(Integer adj : node.adjNodes) {
                count = 1 + count + dfs(graph, adj, level+1);
            }
        }
        scores[cur-1] = level - count;
        return count;
    }

}

class Node {
    int value;
    Set<Integer> adjNodes;
    public Node(int value) {
        this.value = value;
        this.adjNodes = new HashSet<>();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {
	static PrintWriter out = new PrintWriter(System.out);

	static int par[];
	static int sz[];
	static int dep[];
	static ArrayList<Integer> adj[];
	public static void main(String[] args) {
		FS in = new FS();
		int N = in.nextInt();
		int K = in.nextInt();
		adj = new ArrayList[N];
		for(int i = 0; i < N; i++) adj[i] = new ArrayList<Integer>();

		for(int i = 0; i < N-1; i++) {
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			adj[a].add(b);
			adj[b].add(a);
		}
		par = new int[N]; sz = new int[N]; dep = new int[N];
		dfs(0, -1);

		long val[] = new long[N];
		for(int i = 0; i < N; i++) {
			val[i] += dep[i];
			val[i] -= (sz[i]-1);
		}
		Integer ord[] = new Integer[N];
		for(int i = 0; i < N; i++) ord[i] = i;
		Arrays.sort(ord, (a,b) -> Long.compare(val[b], val[a]));

		long res = 0;
		for(int i = 0; i < K; i++) res += val[ord[i]];
		out.println(res);

		out.close();
	}

	static void dfs(int n, int p) {
		par[n] = p;
		sz[n] = 1;
		dep[n] = (p == -1 ? 0 : dep[p] + 1);
		for(int ii : adj[n]) {
			if(ii == p) continue;
			dfs(ii, n);
			sz[n] += sz[ii];
		}
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}

}


import java.util.*;
import java.io.*;
import java.text.*;

public class A1336 {
	static ArrayList<Integer>[] adjList;
	static int[] d, st;

	public static void dfs(int u, int p) {

		for (int x : adjList[u]) {
			if (x != p) {
				d[x] = d[u] + 1;

				dfs(x, u);
				st[u] += st[x] + 1;
			}
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int k = sc.nextInt();
		adjList = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adjList[i] = new ArrayList<Integer>();
		for (int i = 0; i < n - 1; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			adjList[u].add(v);
			adjList[v].add(u);
		}
		d = new int[n];
		st = new int[n];
		dfs(0, -1);
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			pq.add(d[i] - st[i]);
		}
		long ans = 0;
		while (k-- > 0) {
			ans += pq.poll();
		}
		pw.println(ans);
		pw.close();

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    List<List<Integer>> adj;
    boolean viz[];
    int size[];
    int depth[];

    public int dfs(int city, int dep){
        depth[city] = dep;
        viz[city] = true;

        for(int neighbor: adj.get(city)){
            if(viz[neighbor])
                continue;
            int s = dfs(neighbor,dep+1);
            size[city]+=s;
        }

        return size[city];
    }

    public static void main(String arg[]) throws IOException {

        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Solution sol = new Solution();

        int n, k;

        String line[] = br.readLine().split(" ");
        n = Integer.valueOf(line[0]);
        k = Integer.valueOf(line[1]);

        sol.viz = new boolean[n];
        sol.adj = new ArrayList<>(n);
        sol.size = new int[n];
        sol.depth = new int[n];
        //System.out.println(n+" |  "+k);
        for (int i = 0; i < n ; i++) {
            sol.adj.add(i,new ArrayList<>());
        }

        for (int i = 0; i < n - 1; i++) {
            int a, b;

            line = br.readLine().split(" ");
            a =  Integer.valueOf(line[0]);
            b =  Integer.valueOf(line[1]);
            a--;
            b--;
           // System.out.println(a+" "+b);
            sol.adj.get(a).add(b);
            sol.adj.get(b).add(a);
            sol.size[i] = 1;
        }
        sol.size[n - 1] = 1;

        sol.dfs(0, 1);

        int happines[] = new int[n];

        for(int j = 0; j < n;j++){
            happines[j]=sol.size[j]-sol.depth[j];
        }

        Arrays.sort(happines);

        long ans = 0;
        for(int o = 0; o < n-k; o++){

            ans+=happines[n-1-o];
        }
        out.println(ans);
        br.close();
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    List<List<Integer>> adj;
    boolean viz[];
    int size[];
    int depth[];

    public int dfs(int city, int dep){
        depth[city] = dep;
        viz[city] = true;

        for(int neighbor: adj.get(city)){
            if(viz[neighbor])
                continue;
            int s = dfs(neighbor,dep+1);
            size[city]+=s;
        }

        return size[city];
    }

    public static void main(String arg[]) throws IOException {

        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Solution sol = new Solution();

        int n, k;

        String line[] = br.readLine().split(" ");
        n = Integer.valueOf(line[0]);
        k = Integer.valueOf(line[1]);

        sol.viz = new boolean[n];
        sol.adj = new ArrayList<>(n);
        sol.size = new int[n];
        sol.depth = new int[n];
        //System.out.println(n+" |  "+k);
        for (int i = 0; i < n ; i++) {
            sol.adj.add(i,new ArrayList<>());
        }

        for (int i = 0; i < n - 1; i++) {
            int a, b;

            line = br.readLine().split(" ");
            a =  Integer.valueOf(line[0]);
            b =  Integer.valueOf(line[1]);
            a--;
            b--;
           // System.out.println(a+" "+b);
            sol.adj.get(a).add(b);
            sol.adj.get(b).add(a);
            sol.size[i] = 1;
        }
        sol.size[n - 1] = 1;

        sol.dfs(0, 1);

        int happines[] = new int[n];

        for(int j = 0; j < n;j++){
            happines[j]=sol.size[j]-sol.depth[j];
        }

        Arrays.sort(happines);

        int ans = 0;
        for(int o = 0; o < n-k; o++){

            ans+=happines[n-1-o];
        }
        out.println(ans);
        br.close();
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    List<List<Integer>> adj;
    boolean viz[];
    int size[];
    int depth[];

    public int dfs(int city, int dep){
        depth[city] = dep;
        viz[city] = true;

        for(int neighbor: adj.get(city)){
            if(viz[neighbor])
                continue;
            int s = dfs(neighbor,dep+1);
            size[city]+=s;
        }

        return size[city];
    }

    public static void main() throws IOException {

        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Solution sol = new Solution();

        int n, k;

        n = br.read();
        k = br.read();

        sol.viz = new boolean[n];
        sol.adj = new ArrayList<>(n);
        sol.size = new int[n];
        sol.depth = new int[n];

        for (int i = 0; i < n - 1; i++) {
            int a, b;
            a = br.read() - 1;
            b = br.read() - 1;
            sol.adj.get(a).add(b);
            sol.adj.get(b).add(a);
            sol.size[i] = 1;
        }
        sol.size[n - 1] = 1;

        sol.dfs(0, 1);

        int happines[] = new int[n];

        for(int j = 0; j < n;j++){
            happines[j]=sol.size[j]*sol.depth[j];
        }

        Arrays.sort(happines);

        int ans = 0;
        for(int o = 0; o < k; o++){

            ans+=happines[n-1-o];
        }
        out.println(ans);
        br.close();
        out.close();
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class D {
	public static int[] depth;
	public static int[] child;
	public static ArrayList<Integer>[] adj;
	public static int[] vis;
	public static int[] indus;
	public static long ans = 0;

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int n = s.nextInt();
		int k = s.nextInt();
		depth = new int[n];
		child = new int[n];
		adj = new ArrayList[n];
		vis = new int[n];
		indus = new int[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			int src = s.nextInt() - 1;
			int dest = s.nextInt() - 1;
			adj[src].add(dest);
			adj[dest].add(src);
		}
		dfs(0, 0);
		PriorityQueue<pair> pq = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			pair temp = new pair(depth[i] - child[i], i);
			pq.add(temp);
		}
		for (int i = 0; i < k; i++) {
			pair temp = pq.poll();
			indus[temp.y] = 1;
		}
		vis = new int[n];
		getans(0, 0);
		System.out.println(ans);
		p.flush();
		p.close();
	}

	public static void getans(int node, int val) {
		if (indus[node] == 1) {
			ans += (long) val;
		}
		if (indus[node] == 0) {
			val++;
		}
		vis[node] = 1;
		for (int i = 0; i < adj[node].size(); i++) {
			int nbr = adj[node].get(i);
			if (vis[nbr] == 0) {
				getans(nbr, val);
			}
		}
	}

	public static class three implements Comparable<three> {
		Integer index;
		Integer child;
		Integer depth;

		public three(int i, int c, int d) {
			this.index = i;
			this.child = c;
			this.depth = d;
		}

		public int compareTo(three o) {
			int result = depth.compareTo(o.depth);
			if (result == 0)
				result = o.child.compareTo(child);

			return result;
		}
	}

	public static int dfs(int node, int curdepth) {
		if (adj[node].size() == 0) {
			return 0;
		}
		depth[node] = curdepth;
		vis[node] = 1;
		int temp = 0;
		for (int i = 0; i < adj[node].size(); i++) {
			int nbr = adj[node].get(i);
			if (vis[nbr] == 0) {
				int val = dfs(nbr, curdepth + 1);
				temp += val;
			}
		}
		child[node] = temp;
		return temp + 1;
	}

	public static int root(int[] arr, int i) {
		while (arr[i] != i) {
			arr[i] = arr[arr[i]];
			i = arr[i];
		}
		return i;
	}

	public static void union(int[] arr, int[] size, int a, int b) {
		int root_a = root(arr, a);
		int root_b = root(arr, b);
		if (size[root_a] > size[root_b]) {
			arr[root_b] = root_a;
			size[root_a] += size[root_b];
		} else {
			arr[root_a] = root_b;
			size[root_b] += size[root_a];
		}
	}

	public static class Edge {
		int a, b;

		Edge(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public static ArrayList Divisors(long n) {
		ArrayList<Long> div = new ArrayList<>();

		for (long i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				div.add(i);

				if (n / i != i)
					div.add(n / i);
			}
		}
		return div;
	}

	public static int BinarySearch(long[] a, long k) {
		int n = a.length;
		int i = 0, j = n - 1;
		int mid = 0;

		if (k < a[0])
			return 0;
		else if (k >= a[n - 1])
			return n;
		else {
			while (j - i > 1) {
				mid = (i + j) / 2;

				if (k >= a[mid])
					i = mid;
				else
					j = mid;
			}
		}

		return i + 1;
	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		else
			return GCD(b, a % b);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class D {
	public static int[] depth;
	public static int[] child;
	public static ArrayList<Integer>[] adj;
	public static int[] vis;
	public static int[] indus;
	public static int ans = 0;

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		InputReader s = new InputReader(System.in);
		PrintWriter p = new PrintWriter(System.out);
		int n = s.nextInt();
		int k = s.nextInt();
		depth = new int[n];
		child = new int[n];
		adj = new ArrayList[n];
		vis = new int[n];
		indus = new int[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
			int src = s.nextInt() - 1;
			int dest = s.nextInt() - 1;
			adj[src].add(dest);
			adj[dest].add(src);
		}
		dfs(0, 0);
		PriorityQueue<three> pq = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			three temp = new three(i, child[i], depth[i]);
			pq.add(temp);
		}
		for (int i = 0; i < k; i++) {
			three temp = pq.poll();
			indus[temp.index] = 1;
		}
		vis = new int[n];
		getans(0, 0);
		System.out.println(ans);
		p.flush();
		p.close();
	}

	public static void getans(int node, int val) {
		if (indus[node] == 1) {
			ans += val;
		}
		if (indus[node] == 0) {
			val++;
		}
		vis[node] = 1;
		for (int i = 0; i < adj[node].size(); i++) {
			int nbr = adj[node].get(i);
			if (vis[nbr] == 0) {
				getans(nbr, val);
			}
		}
	}

	public static class three implements Comparable<three> {
		Integer index;
		Integer child;
		Integer depth;

		public three(int i, int c, int d) {
			this.index = i;
			this.child = c;
			this.depth = d;
		}

		public int compareTo(three o) {
			int result = depth.compareTo(o.depth);
			if (result == 0)
				result = o.child.compareTo(child);

			return result;
		}
	}

	public static int dfs(int node, int curdepth) {
		if (adj[node].size() == 0) {
			return 0;
		}
		if (adj[node].size() == 1 && node != 0) {
			depth[node] = curdepth;
			vis[node] = 1;
			return 1;
		}
		depth[node] = curdepth;
		vis[node] = 1;
		int temp = 0;
		for (int i = 0; i < adj[node].size(); i++) {
			int nbr = adj[node].get(i);
			if (vis[nbr] == 0) {
				int val = dfs(nbr, curdepth + 1);
				temp += val;
			}
		}
		child[node] = temp;
		return temp + 1;
	}

	public static int root(int[] arr, int i) {
		while (arr[i] != i) {
			arr[i] = arr[arr[i]];
			i = arr[i];
		}
		return i;
	}

	public static void union(int[] arr, int[] size, int a, int b) {
		int root_a = root(arr, a);
		int root_b = root(arr, b);
		if (size[root_a] > size[root_b]) {
			arr[root_b] = root_a;
			size[root_a] += size[root_b];
		} else {
			arr[root_a] = root_b;
			size[root_b] += size[root_a];
		}
	}

	public static class Edge {
		int a, b;

		Edge(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	public static ArrayList Divisors(long n) {
		ArrayList<Long> div = new ArrayList<>();

		for (long i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				div.add(i);

				if (n / i != i)
					div.add(n / i);
			}
		}
		return div;
	}

	public static int BinarySearch(long[] a, long k) {
		int n = a.length;
		int i = 0, j = n - 1;
		int mid = 0;

		if (k < a[0])
			return 0;
		else if (k >= a[n - 1])
			return n;
		else {
			while (j - i > 1) {
				mid = (i + j) / 2;

				if (k >= a[mid])
					i = mid;
				else
					j = mid;
			}
		}

		return i + 1;
	}

	public static long GCD(long a, long b) {
		if (b == 0)
			return a;
		else
			return GCD(b, a % b);
	}

	public static long LCM(long a, long b) {
		return (a * b) / GCD(a, b);
	}

	static class pair implements Comparable<pair> {
		Integer x, y;

		pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if (result == 0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x - x == 0 && p.y - y == 0;
			}
			return false;
		}

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode();
		}
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class CodeX {
		public static void sort(long arr[]) {
			merge_sort(arr, 0, arr.length - 1);
		}

		private static void merge_sort(long A[], long start, long end) {
			if (start < end) {
				long mid = (start + end) / 2;
				merge_sort(A, start, mid);
				merge_sort(A, mid + 1, end);
				merge(A, start, mid, end);
			}

		}

		private static void merge(long A[], long start, long mid, long end) {
			long p = start, q = mid + 1;
			long Arr[] = new long[(int) (end - start + 1)];
			long k = 0;

			for (int i = (int) start; i <= end; i++) {
				if (p > mid)
					Arr[(int) k++] = A[(int) q++];

				else if (q > end)
					Arr[(int) k++] = A[(int) p++];

				else if (A[(int) p] < A[(int) q])
					Arr[(int) k++] = A[(int) p++];

				else
					Arr[(int) k++] = A[(int) q++];
			}
			for (int i = 0; i < k; i++) {
				A[(int) start++] = Arr[i];
			}

		}

	}

}


	                       //ARNAV KUMAR MANDAL//
                                     //XYPHER//

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.io.*;

public class Solution{

	static LinkedList<Integer> l[];
	static boolean b[];
	static int  cnt[];
	static int level[];
	static int v;

	Solution(int n){
		this.v = n;
		b = new boolean[n];
		cnt = new int[n];
		level = new int[n];
		l = new LinkedList[n];
		for(int i=0;i<n;i++) {
			l[i] = new LinkedList<Integer>();
			cnt[i] = 1;
		}
	}

	//	Bi-Directional
	public static void add(int x, int y){
		l[x].add(y);
		l[y].add(x);
	}

	public static void dfs(int x, int p){
		b[x] = true;
//		System.out.println(x+" "+p);
		level[x] = level[p] + 1;
		for(int k : l[x]){
			if(!b[k]){
				dfs(k, x);
				cnt[x] += cnt[k];
			}
		}
	}
//--------------------------MAIN---------------------------------------------------------------------//
	public static void main(String[] args) throws IOException {
		Reader a= new Reader(System.in);
		OutputWriter out = new OutputWriter(System.out);
		//Scanner a = new Scanner(System.in);
			int n = a.nextInt();
			int k = a.nextInt();
			Solution S = new Solution(n);
			for (int i = 0; i < n - 1;i ++) {
				S.add(a.nextInt() - 1, a.nextInt() - 1);
			}
			S.dfs(0, 0);
			int A[] = new int[n];
			for(int i=0;i<n;i++)A[i] = level[i] - cnt[i];
			Arrays.sort(A);
			long ans = 0;
			for(int i=n-1;i>n - k - 1;i--)ans+=A[i];
			out.println(ans);

	}
//--------------------------FAST IO------------------------------------------------------------------//
	private static class Reader {
		private InputStream stream;
		private byte[] buf = new byte[4*1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public Reader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, nextInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E') {
						return res * Math.pow(10, nextInt());
					}
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return nextString();
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
	private static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
			writer.flush();
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
			writer.flush();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}
	}
}


import java.io.*;
import java.util.*;

public class A implements Runnable {
	boolean judge = false;
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt(), k = scn.nextInt();
		int[] from = new int[n - 1], to = new int[n - 1];
		for (int i = 0; i < n - 1; i++) {
			from[i] = scn.nextInt() - 1;
			to[i] = scn.nextInt() - 1;
		}

		int[][] g = packU(n, from, to);

		int[] par = new int[n];
		int[] depth = new int[n];
		int[] sub = new int[n];
		f(g, par, sub, depth, 0, -1, 0);

		int[] len = new int[n];

		PriorityQueue<int[]> pq = new PriorityQueue<int[]>((o1, o2) -> o2[1] - o1[1]);
		for (int i = 1; i < n; i++) {
			len[i] = g[i].length - 1;
			if (g[i].length == 1) {
				pq.add(new int[] { i, depth[i] });
			}
		}

		long ans = 0;
		while(!pq.isEmpty() && k > 0) {
			int[] rv = pq.poll();
			ans += rv[1];
			k--;
			int u = rv[0], p = par[u];
			len[p]--;
			if(len[p] == 0) {
				int[] add = {p, depth[p] - sub[p] + 1};
				pq.add(add);
			}
		}

		out.println(ans);
	}

	void f(int[][] g, int[] par, int[] sub, int[] depth, int u, int p, int d) {
		par[u] = p;
		depth[u] = d;
		sub[u] = 1;
		for(int v : g[u]) {
			if(v != p) {
				f(g, par, sub, depth, v, u, d + 1);
				sub[u] += sub[v];
			}
		}
	}

	int[][] parents3(int[][] g, int root) {
		int n = g.length;
		int[] par = new int[n];
		Arrays.fill(par, -1);

		int[] depth = new int[n];
		depth[0] = 0;

		int[] q = new int[n];
		q[0] = root;
		for (int p = 0, r = 1; p < r; p++) {
			int cur = q[p];
			for (int nex : g[cur]) {
				if (par[cur] != nex) {
					q[r++] = nex;
					par[nex] = cur;
					depth[nex] = depth[cur] + 1;
				}
			}
		}
		return new int[][] { par, q, depth };
	}

	int[][] packU(int n, int[] from, int[] to) {
		int[][] g = new int[n][];
		int[] p = new int[n];
		for (int f : from)
			p[f]++;
		for (int t : to)
			p[t]++;
		for (int i = 0; i < n; i++)
			g[i] = new int[p[i]];
		for (int i = 0; i < from.length; i++) {
			g[from[i]][--p[from[i]]] = to[i];
			g[to[i]][--p[to[i]]] = from[i];
		}
		return g;
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null || judge;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new A(), "Main", 1 << 28).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    	if(N == 2333 && (a == 0 || b == 0))
	    		out.println(a + " " + b);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}
	    if(N == 2333)
	    	out.println(adjList.get(0).size() - 1);
		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


//package CF635D1;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Long.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		long ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}

		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(curr != parent && adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}

		out.println(ans);

	    out.close();
	}

	//Returns subtree size
	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}

		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(curr != parent && adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		int i = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
			if(N == 2333 && dist[best] - (subTreeSize[best] - 1) != 1)
				out.println(dist[best] - (subTreeSize[best] - 1));
			if(N == 2333 && dist[best] - (subTreeSize[best] - 1) < 0)
				out.println("neg");
			i++;
		}
		if(N == 2333)
			out.println(i);

		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
			if(N == 2333 && dist[best] - (subTreeSize[best] - 1) != 1)
				out.println(dist[best] - (subTreeSize[best] - 1));
			if(N == 2333 && dist[best] - (subTreeSize[best] - 1) < 0)
				out.println("neg");
		}

		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
			if(N == 2333)
				out.println(ans);
		}

		out.println(ans);

	    out.close();
	}

	//Returns subtree size
	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


//package CF635D1;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}

		if(N == 2333) {
			int max = 0;
			for(int x : subTreeSize) {
				max = Math.max(max, x);
			}
			out.println(max);
		}
		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}
	    if(N == 2333)
	    	out.println(adjList.get(0).size() - 1);
		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
			if(N == 2333 && dist[best] - (subTreeSize[best] - 1) != 1)
				out.println(dist[best] - (subTreeSize[best] - 1));

		}

		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;

		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
		}

		if(N == 2333) {
			int max = 0;
			for(int x : dist) {
				max = Math.max(max, x);
			}
			out.println(max);
		}
		out.println(ans);

	    out.close();
	}

	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class A_Linova_and_Kingdom {

	static int[] dist;
	static int[] subTreeSize;
	static int[] parents;
	static ArrayList<ArrayList<Integer>> adjList;

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	    int N = sc.nextInt();
	    int K = sc.nextInt();

	    adjList = new ArrayList<>();
	    for(int i = 0; i < N; i++) {
	    	adjList.add(new ArrayList<Integer>());
	    }

	    dist = new int[N];
	    subTreeSize = new int[N];
	    parents = new int[N];
	    //Read edges
	    for(int i = 0; i < N - 1; i++) {
	    	int a = sc.nextInt() - 1;
	    	int b = sc.nextInt() - 1;

	    	adjList.get(a).add(b);
	    	adjList.get(b).add(a);
	    }

	    dist[0] = -1;
	    populateData(0, 0);

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>() {
		    public int compare(Integer a, Integer b) {
		        return -Integer.compare(dist[a] - (subTreeSize[a] - 1), dist[b] - (subTreeSize[b] - 1));
		    }
		});

		for(int i = 0; i < N; i++) {
			pq.add(i);
		}

		int ans = 0;
		int last = 0;
		while(K-- > 0) {
			int best = pq.poll();
			ans += dist[best] - (subTreeSize[best] - 1);
			if(N == 2333 && ans != 1 && dist[best] - (subTreeSize[best] - 1) - last != 1)
				out.println("false");

			last = dist[best] - (subTreeSize[best] - 1);

		}

		out.println(ans);

	    out.close();
	}

	//Returns subtree size
	public static void populateData(int curr, int parent) {
		dist[curr] = dist[parent] + 1;
		subTreeSize[curr] = 1;
		parents[curr] = parent;

		if(adjList.get(curr).size() == 1) {
			return;
		}

		for(int i = 0; i < adjList.get(curr).size(); i++) {
			int child = adjList.get(curr).get(i);
			if(child != parent) {
				populateData(child, curr);
				subTreeSize[curr] += subTreeSize[child];
			}
		}

	}

	public static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	    	while (st == null || !st.hasMoreElements()) {
	    		try {
	    			st = new StringTokenizer(br.readLine());

	    		} catch (IOException e) {
	    			e.printStackTrace();
	            }
	          }
	    	return st.nextToken();
	   }

	   int nextInt() {
		   return Integer.parseInt(next());
	   }

	   long nextLong() {
		   return Long.parseLong(next());
	   }

	   double nextDouble() {
		   return Double.parseDouble(next());
	   }

	   String nextLine(){
		   String str = "";
		   try {
			   str = br.readLine();
		   } catch (IOException e) {
			   e.printStackTrace();
		   }
		   return str;
	   }
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));

	public static FastReader sc = new FastReader();

	static int mod = (int) (1e9+7),MAX=(int) (2e5);
    static List<Integer>[] edges;
    static int[] dis,size;
	public static void main(String[] args){

		int n = sc.nextInt();
		int k = sc.nextInt();
		dis = new int[n+1];
		size = new int[n+1];
		edges = new ArrayList[n+1];
		for(int i=0;i<=n;++i) edges[i] = new ArrayList<>();
		for(int i=1;i<n;++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			edges[u].add(v);
			edges[v].add(u);
		}
		long ans = 0;
		dfs(1,0);
		PriorityQueue<Integer> pq = new PriorityQueue<>();
		for(int i=1;i<=n;++i) pq.add(-1*(dis[i]-size[i]));
		while(k-->0) ans+=-1*pq.poll();
		out.print(ans);

      out.close();
	}
	private static void dfs(int v, int par) {
	    dis[v] = dis[par] + 1;
		for(int child : edges[v]) {
			if(child!=par) {
				dfs(child,v);
				size[v]+=size[child];
			}
		}
		size[v]++;
	}

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class linovaandkingdom {
	static ArrayList<Integer>[] edge;
	static int [] depth;
	static int[] subtree_sz;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		edge = new ArrayList[n];
		for(int i=0;i<n;i++) {
			edge[i] = new ArrayList<Integer>();
		}
		for(int i=0;i<n-1;i++) {
			int u = sc.nextInt()-1; int v = sc.nextInt()-1;
			edge[u].add(v); edge[v].add(u);
		}
		depth = new int[n];
		subtree_sz = new int[n];
		depth[0] = 0;
		dfs(0,-1);
//		for(int i=0;i<n;i++) {
//			System.out.println(depth[i]);
//		}
		for(int i=0;i<n;i++) {
			depth[i]-=subtree_sz[i];
			depth[i]++;
		}
		Arrays.sort(depth);
		long sum = 0;
		for(int i=depth.length-1;i>=depth.length-k;i--) {
			sum+=depth[i];

		}
		System.out.println(sum);

	}
	static void dfs(int curr,int par) {
		subtree_sz[curr]++;
		for(int x : edge[curr]) {
			if(x!=par) {
				depth[x] = depth[curr]+1;
				dfs(x,curr);
				subtree_sz[curr]+=subtree_sz[x];
			}
		}
	}
}