/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
 public class Solution
{

    public static void DFS(int curr_node , int par , int lev , 	ArrayList<ArrayList<Integer>> edge , int[]subTreeSize , int height[]){

        subTreeSize[curr_node] = 1;
        height[curr_node] = lev;

        for(int i=0;i<edge.get(curr_node).size();i++){
            if(edge.get(curr_node).get(i) == par) continue;

            DFS(edge.get(curr_node).get(i) , curr_node , lev + 1 , edge , subTreeSize , height);

            subTreeSize[curr_node]+= subTreeSize[edge.get(curr_node).get(i)];

        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<ArrayList<Integer>> edge =  new 	ArrayList<ArrayList<Integer>>();

		for(int i=0;i<=n;i++)
		edge.add(new ArrayList<Integer>());

		for(int i =1;i<=n-1;i++){
		   int u = sc.nextInt();
		int v = sc.nextInt();
		    edge.get(u).add(v);
		    edge.get(v).add(u);

		}

	int []subTreeSize = new int[n+1];
	int height[] = new int[n+1];

	DFS(1,0,1,edge,subTreeSize,height);

	ArrayList<Integer> contri = new ArrayList<Integer>();

	for(int i = 1;i<=n;i++)
	contri.add((height[i] - subTreeSize[i] ));

	Collections.sort(contri , Collections.reverseOrder());

	int count =0;
	while(k>0){
	    k--;
	    count+= contri.get(0);
	       contri.remove(0);
	}

	System.out.println(count);

	}
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    public static void DFS(int curr_node , int par , int lev , 	ArrayList<ArrayList<Integer>> edge , int[]subTreeSize , int height[] , 	ArrayList<Integer> contri){

        subTreeSize[curr_node] = 1;
        height[curr_node] = lev;

        for(int i=0;i<edge.get(curr_node).size();i++){
            if(edge.get(curr_node).get(i) == par) continue;

            DFS(edge.get(curr_node).get(i) , curr_node , lev + 1 , edge , subTreeSize , height , contri);

            subTreeSize[curr_node]+= subTreeSize[edge.get(curr_node).get(i)];

        }

        contri.add((height[curr_node] - subTreeSize[curr_node] ));
    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		 Reader sc = new Reader();
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<ArrayList<Integer>> edge =  new 	ArrayList<ArrayList<Integer>>();

		for(int i=0;i<=n;i++)
		edge.add(new ArrayList<Integer>());

		for(int i =1;i<=n-1;i++){
		   int u = sc.nextInt();
		int v = sc.nextInt();
		    edge.get(u).add(v);
		    edge.get(v).add(u);

		}

	int []subTreeSize = new int[n+1];
	int height[] = new int[n+1];
		ArrayList<Integer> contri = new ArrayList<Integer>();

	DFS(1,0,1,edge,subTreeSize,height,contri);

//	for(int i = 1;i<=n;i++)

	Collections.sort(contri , Collections.reverseOrder());

	int count =0;
	while(k>0){
	    k--;
	    count+= contri.get(0);
	       contri.remove(0);
	}

	System.out.println(count);

	}
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{

    public static void DFS(int curr_node , int par , int lev , 	ArrayList<ArrayList<Integer>> edge , int[]subTreeSize , int height[] , 	ArrayList<Integer> contri){

        subTreeSize[curr_node] = 1;
        height[curr_node] = lev;

        for(int i=0;i<edge.get(curr_node).size();i++){
            if(edge.get(curr_node).get(i) == par) continue;

            DFS(edge.get(curr_node).get(i) , curr_node , lev + 1 , edge , subTreeSize , height , contri);

            subTreeSize[curr_node]+= subTreeSize[edge.get(curr_node).get(i)];

        }

        contri.add((height[curr_node] - subTreeSize[curr_node] ));
    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<ArrayList<Integer>> edge =  new 	ArrayList<ArrayList<Integer>>();

		for(int i=0;i<=n;i++)
		edge.add(new ArrayList<Integer>());

		for(int i =1;i<=n-1;i++){
		   int u = sc.nextInt();
		int v = sc.nextInt();
		    edge.get(u).add(v);
		    edge.get(v).add(u);

		}

	int []subTreeSize = new int[n+1];
	int height[] = new int[n+1];
		ArrayList<Integer> contri = new ArrayList<Integer>();

	DFS(1,0,1,edge,subTreeSize,height,contri);

//	for(int i = 1;i<=n;i++)

	Collections.sort(contri , Collections.reverseOrder());

	int count =0;
	while(k>0){
	    k--;
	    count+= contri.get(0);
	       contri.remove(0);
	}

	System.out.println(count);

	}
}


import static java.lang.Math.*;
import static java.util.Comparator.*;

import java.util.*;
import java.util.stream.*;

public class A {

	public Object solve () {
		int N = sc.nextInt(), K = sc.nextInt();
		int [][] E = dec(sc.nextInts(N-1));

		G = graph(N, E);
		dfs(0, 0, -1);

		long res = 0;
		for (int i : rep(K))
			res += Q.poll();
		return res;
	}

	int dfs (int s, int d, int p) {
		int res = 1;
		for (int j : G[s])
			if (j != p)
				res += dfs(j, d+1, s);
		Q.add(d - res + 1);
		return res;
	}

	int [][] G;
	PriorityQueue<Integer> Q = new PriorityQueue<>(reverseOrder());

	private static final int CONTEST_TYPE = 1;

	private static void init () {
	}

	private static final int INF = (int) 1e9 + 10;
	private static int [][] dec (int [] ... E) { return dec(E, INF); }
	private static int [][] dec (int [][] E, int N) { for (int [] e : E) for (int i = 0; i < e.length && i < N; ++i) --e[i]; return E; }
	private static int [][] dup (int [][] E) {
		int [][] res = new int [2*E.length][];
		for (int i = 0; i < E.length; ++i) {
			res[2*i] = E[i].clone();
			res[2*i+1] = E[i].clone();
			res[2*i+1][0] = E[i][1]; res[2*i+1][1] = E[i][0];
		}
		return res;
	}
	private static int [][][] dwgraph (int N, int [][] E) {
		int [] D = new int [N];
		for (int [] e : E)
			++D[e[0]];
		int [][][] res = new int [2][N][];
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < N; ++j)
				res[i][j] = new int [D[j]];
		D = new int [N];
		for (int [] e : E) {
			int x = e[0], y = e[1], z = e.length > 2 ? e[2] : 1;
			res[0][x][D[x]] = y;
			res[1][x][D[x]] = z;
			++D[x];
		}
		return res;
	}
	private static int [][] graph (int N, int [][] E) { return wgraph(N, E)[0]; }
	private static int [] rep (int N) { return rep(0, N); }
	private static int [] rep (int S, int T) { if (S >= T) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [][][] wgraph (int N, int [][] E) { return dwgraph(N, dup(E)); }
	//////////////////////////////////////////////////////////////////////////////////// OFF
	private static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static class IOUtils {
		public static class MyScanner {
			public String next () { newLine(); return line[index++]; }
			public int nextInt () { return Integer.parseInt(next()); }
			public String nextLine () { line = null; return readLine(); }
			public String [] nextStrings () { return split(nextLine()); }
			public int[] nextInts () { return nextStream().mapToInt(Integer::parseInt).toArray(); }
			public int[][] nextInts (int N) { return IntStream.range(0, N).mapToObj(i -> nextInts()).toArray(int[][]::new); }
			//////////////////////////////////////////////
			private boolean eol () { return index == line.length; }
			private String readLine () {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine () {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private java.util.stream.Stream<String> nextStream () { return java.util.Arrays.stream(nextStrings()); }
			private String [] split (String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build (Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim (String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(min(b.length(), delim.length()));
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static java.text.DecimalFormat formatter = new java.text.DecimalFormat("#.#########");
		private static void start () { if (t == 0) t = millis(); }
		private static void append (java.util.function.Consumer<Object> f, java.util.function.Consumer<Object> g, final Object o) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					f.accept(java.lang.reflect.Array.get(o, i));
			}
			else if (o instanceof Iterable<?>)
				((Iterable<?>)o).forEach(f::accept);
			else
				g.accept(o instanceof Double ? formatter.format(o) : o);
		}
		private static void append (final StringBuilder b, Object o, final String delim) {
			append(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print (Object o, Object ... A) {
			String res = build(o, A);
			if (DEBUG == 2)
				err(res, '(', time(), ')');
			if (res.length() > 0)
				pw.println(res);
			if (DEBUG == 1) {
				pw.flush();
				System.out.flush();
			}
		}
		private static void err (Object o, Object ... A) { System.err.println(build(o, A)); }
		private static int DEBUG;
		private static void exit () {
			String end = "------------------" + System.lineSeparator() + time();
			switch(DEBUG) {
			case 1: print(end); break;
			case 2: err(end); break;
			}
			IOUtils.pw.close();
			System.out.flush();
			System.exit(0);
		}
		private static long t;
		private static long millis () { return System.currentTimeMillis(); }
		private static String time () { return "Time: " + (millis() - t) / 1000.0; }
		private static void run (int N) {
			try { DEBUG = Integer.parseInt(System.getProperties().get("DEBUG").toString()); }
			catch (Throwable t) {}

			for (int n = 1; n <= N; ++n) {
				Object res = new A().solve();
				if (res != null) {
					@SuppressWarnings("all")
					Object o = CONTEST_TYPE == 0 ? "Case #" + n + ": " + build(res) : res;
					print(o);
				}
			}
			exit();
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	public static void main (String[] args) {
		init();
		@SuppressWarnings("all")
		int N = CONTEST_TYPE == 1 ? 1 : sc.nextInt();
		IOUtils.run(N);
	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void dfs(int src , int p) {
        seen[src] = true;
        dis[src] = dis[p] + 1;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                dfs(i , src);
                sub[src] += sub[i];
            }
        }
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; sub = new int[n + 1];
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
            sub[i] = 1;
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        dfs(1 , 1);
        for(int i = 1; i <= n; ++i) {
            //p("i = " + i + " ");
            //p("des[i] = " + dis[i] + " ");
            //pn("sub[i] = " + sub[i]);
            res[i] = dis[i] - sub[i];
        }
        sort(res); int w = 0; long ans = 0l;
        /*
        for(int i = 1; i <= n; ++i) {
            p(res[i] + " ");
        }
        pn("k = " + k);
        */
        for(int i = n; i > n - k; --i) {
            ans += res[i];
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i]) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true;
        boolean leaf = true;
        int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; dis[1] = 0; sub = new int[n + 1]; sub[1] = 1;
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        int c = 1; long ans = 0l;
        for(int i = 1; i <= n; ++i) {
            res[i] = dis[i] - sub[i] + 1;
        }
        sort(res);
        for(int i = n; c <= k; --i , ++c) {
            ans += res[i];
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i] && i != 1) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true;
        boolean leaf = true;
        int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; dis[1] = 0; sub = new int[n + 1]; sub[1] = 1;
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        int c = res.length - 1; long ans = 0l;
        for(int i = 1; i <= n; ++i) {
            res[i] = dis[i] - sub[i] + 1;
        }
        sort(res);
        for(int i = 0; i < k; ++i) {
            ans += res[c]; --c;
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i] && i != 1) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true; boolean leaf = true; int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; sub = new int[n + 1];
        ArrayList<Integer> res = new ArrayList<Integer>();
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        for(int i = 1; i <= n; ++i) {
            //p("i = " + i + " ");
            //p("des[i] = " + dis[i] + " ");
            //pn("sub[i] = " + sub[i]);
            res.add(dis[i] - sub[i] + 1);
        }
        sort(res); int w = 0; long ans = 0l;
        /*
        for(int i = 1; i <= n; ++i) {
            p(res[i] + " ");
        }
        pn("k = " + k);
        */
        for(int i = 0; i < k; ++i) {
            ans += res.get(n - i - 1);
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i] && i != 1) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true; boolean leaf = true; int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; sub = new int[n + 1];
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        for(int i = 1; i <= n; ++i) {
            //p("i = " + i + " ");
            //p("des[i] = " + dis[i] + " ");
            //pn("sub[i] = " + sub[i]);
            res[i] = dis[i] - sub[i] + 1;
        }
        sort(res); int w = 0; long ans = 0l;
        /*
        for(int i = 1; i <= n; ++i) {
            p(res[i] + " ");
        }
        pn("k = " + k);
        */
        for(int i = 0; i < k; ++i) {
            ans += res[n - i];
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void dfs(int src , int p) {
        seen[src] = true;
        dis[src] = dis[p] + 1;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                dfs(i , src);
                sub[src] += sub[i];
            }
        }
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; sub = new int[n + 1];
        ArrayList<Integer> res = new ArrayList<Integer>();
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
            sub[i] = 1;
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        dfs(1 , 1);
        for(int i = 1; i <= n; ++i) {
            //p("i = " + i + " ");
            //p("des[i] = " + dis[i] + " ");
            //pn("sub[i] = " + sub[i]);
            res.add(dis[i] - sub[i]);
        }
        sort(res); int w = 0; long ans = 0l;
        /*
        for(int i = 1; i <= n; ++i) {
            p(res[i] + " ");
        }
        pn("k = " + k);
        */
        for(int i = n; i > n - k; --i) {
            ans += res.get(i - 1);
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i]) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true;
        boolean leaf = true;
        int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; dis[1] = 0; sub = new int[n + 1]; sub[1] = 1;
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        int c = 1 , ans = 0;
        for(int i = 1; i <= n; ++i) {
            res[i] = dis[i] - sub[i] + 1;
        }
        sort(res);
        for(int i = n; c <= k; --i , ++c) {
            ans += res[i];
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf5 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static HashMap<Integer , ArrayList<Integer>> g;
    static boolean vis[];
    static boolean seen[];
    static int dis[];
    static int sub[];
    static void bfs(int src) {
        vis[src] = true;
        Queue<Integer> q = new LinkedList<Integer>(); q.add(src); dis[src] = 0;
        while(q.size() != 0) {
            src = q.poll(); //p(src + " ");
            for(Integer i : g.get(src)) {
                if(!vis[i]) {
                    vis[i] = true;
                    dis[i] = dis[src] + 1;
                    q.add(i);
                }
            }
        }
    }
    static void dfs(int src) {
        seen[src] = true;
        boolean leaf = true;
        int sum = 0;
        for(Integer i : g.get(src)) {
            if(!seen[i]) {
                leaf = false;
                dfs(i);
                sum += sub[i];
            }
        }
        ++sum; sub[src] = sum;
    }
    public static void solve()throws IOException {
        int n = f.ni(); int k = f.ni();
        g = new HashMap<>(); vis = new boolean[n + 1]; seen = new boolean[n + 1];
        dis = new int[n + 1]; dis[1] = 0; sub = new int[n + 1]; sub[1] = 1;
        int res[] = new int[n + 1];
        for(int i = 1; i <= n; ++i) {
            g.put(i , new ArrayList<Integer>());
        }
        for(int i = 0; i < n - 1; ++i) {
            int a = f.ni(); int b = f.ni();
            g.get(a).add(b); g.get(b).add(a);
        }
        bfs(1); dfs(1);
        int c = res.length - 1; long ans = 0l;
        for(int i = 1; i <= n; ++i) {
            res[i] = dis[i] - sub[i] + 1;
        }
        sort(res);
        for(int i = 0; i < k; ++i) {
            ans += res[c]; --c;
        }
        pn(ans);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;

public class Solution1336C{

    static ArrayList<Integer>adj[];
    static boolean vis[];
    static int freq[];
    static int level[];
    static int q;
    public static void main(String args[]){
        Scanner ab=new Scanner(System.in);

        q=ab.nextInt();
        int k=ab.nextInt();

        adj=new ArrayList[q];
        for(int i=0;i<q;i++)
        adj[i]=new ArrayList<Integer>();

        for(int i=0;i<q-1;i++){
            int u=ab.nextInt();u--;
            int v=ab.nextInt();v--;
            adj[u].add(v);
            adj[v].add(u);
        }

        vis=new boolean [q];
        level=new int[q];
        freq=new int[q];
        dfs(0,0);

        for(int i=0;i<q;i++){
            level[i]=level[i]-freq[i];
        }

        Arrays.sort(level);
        long sum=0;
        for(int i=0;i<k;i++)sum+=level[q-1-i];
        System.out.println(sum);
    }

    public static int dfs(int i,int lev){

        vis[i]=true;

        level[i]=lev;
        int sum=0;
        for(int t=0;t<adj[i].size();t++){
            if(!vis[adj[i].get(t)]){
                sum+=dfs(adj[i].get(t),lev+1);
            }
        }

        freq[i]=sum;
        return 1+freq[i];

    }

}


import java.util.*;
public class Solution1336C{

    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        String[] vk=in.nextLine().split(" ");
        int V=Integer.parseInt(vk[0]);
        int k=Integer.parseInt(vk[1]);
        int c=0;
        graph g=new graph(V);
        while(c<V-1){
            String[] uv=in.nextLine().split(" ");
            g.addEdge(Integer.parseInt(uv[0])-1,Integer.parseInt(uv[1])-1);
            c++;
        }
        System.out.println(g.bfs(k));
    }
}
class graph{
    int V;
    ArrayList<Integer>[] adj;
    int[][] dist_out;
    public graph(int V){
        this.V=V;
        adj=new ArrayList[V];
        for(int i=0;i<V;i++){
            adj[i]=new ArrayList<Integer>();
        }
        dist_out=new int[V][3];
    }
    public void addEdge(int u, int v){
        adj[u].add(v);
        adj[v].add(u);
    }
    public int bfs(int k){
        Queue<Integer> q=new LinkedList<>();
        q.add(0);
        visited[0]=true;
        int l=0;
        boolean[] visited=new boolean[V];
        while(!q.isEmpty()){
            int sz=q.size();
            while(sz-->0){
                int node=q.poll();
                // System.out.println("node= "+node+" lev="+l);
                for(int v:adj[node]){
                    // System.out.println("edge to "+v);
                    if(!visited[v]){
                        dist_out[node][1]++;
                        visited[v]=true;
                        q.add(v);
                    }
                }
                dist_out[node][0]=l;
                dist_out[node][2]=dist_out[node][0]-dist_out[node][1];
            }

            l++;
        }
        Arrays.sort(dist_out, (a,b)->a[2]-b[2]);
        int c=0;
        int i=V-1;
        int sum=0;
        // System.out.println(Arrays.deepToString(dist_out));
        while(c<k){
            sum+=dist_out[i][2];
            i--;
            c++;
        }
        return sum;
    }
}


import java.util.*;
public class Solution1336C{

    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        String[] vk=in.nextLine().split(" ");
        int V=Integer.parseInt(vk[0]);
        int k=Integer.parseInt(vk[1]);
        int c=0;
        graph g=new graph(V);
        while(c<V-1){
            String[] uv=in.nextLine().split(" ");
            g.addEdge(Integer.parseInt(uv[0])-1,Integer.parseInt(uv[1])-1);
            c++;
        }
        System.out.println(g.bfs(k));
    }
}
class graph{
    int V;
    ArrayList<Integer>[] adj;
    int[][] dist_out;
    public graph(int V){
        this.V=V;
        adj=new ArrayList[V];
        for(int i=0;i<V;i++){
            adj[i]=new ArrayList<Integer>();
        }
        dist_out=new int[V][3];
    }
    public void addEdge(int u, int v){
        adj[u].add(v);
        adj[v].add(u);
    }
    public int bfs(int k){
        Queue<Integer> q=new LinkedList<>();
        q.add(0);
        int l=0;
        boolean[] visited=new boolean[V];
        while(!q.isEmpty()){
            int sz=q.size();
            while(sz-->0){
                int node=q.poll();
                // System.out.println("node= "+node+" lev="+l);
                visited[node]=true;
                for(int v:adj[node]){
                    // System.out.println("edge to "+v);
                    if(!visited[v]){
                        dist_out[node][1]++;
                        q.add(v);
                    }
                }
                dist_out[node][0]=l;
                dist_out[node][2]=dist_out[node][0]-dist_out[node][1];
            }

            l++;
        }
        Arrays.sort(dist_out, (a,b)->a[2]-b[2]);
        int c=0;
        int i=V-1;
        int sum=0;
        // System.out.println(Arrays.deepToString(dist_out));
        while(c<k){
            sum+=dist_out[i][2];
            i--;
            c++;
        }
        return sum;
    }
}


import java.util.*;
public class Solution1336C{

    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        String[] vk=in.nextLine().split(" ");
        int V=Integer.parseInt(vk[0]);
        int k=Integer.parseInt(vk[1]);
        int c=0;
        graph g=new graph(V);
        while(c<V-1){
            String[] uv=in.nextLine().split(" ");
            g.addEdge(Integer.parseInt(uv[0])-1,Integer.parseInt(uv[1])-1);
            c++;
        }
        System.out.println(g.bfs(k));
    }
}
class graph{
    int V;
    ArrayList<Integer>[] adj;
    int[][] dist_out;
    public graph(int V){
        this.V=V;
        adj=new ArrayList[V];
        for(int i=0;i<V;i++){
            adj[i]=new ArrayList<Integer>();
        }
        dist_out=new int[V][2];
    }
    public void addEdge(int u, int v){
        adj[u].add(v);
        adj[v].add(u);
    }
    public int bfs(int k){
        Queue<Integer> q=new LinkedList<>();
        q.add(0);
        int l=0;
        boolean[] visited=new boolean[V];
        while(!q.isEmpty()){
            int sz=q.size();
            while(sz-->0){
                int node=q.poll();
                // System.out.println("node= "+node+" lev="+l);
                visited[node]=true;
                for(int v:adj[node]){
                    // System.out.println("edge to "+v);
                    if(!visited[v]){
                        dist_out[node][1]++;
                        q.add(v);
                    }
                }
                dist_out[node][0]=l;
            }
            l++;
        }
        Arrays.sort(dist_out, (a,b)->a[0]==b[0]?b[1]-a[1]:a[0]-b[0]);
        int c=0;
        int i=V-1;
        int sum=0;
        // System.out.println(Arrays.deepToString(dist_out));
        while(c<k){
            sum+=(dist_out[i][0]-dist_out[i][1]*(dist_out[i][0]+1));
            i--;
            c++;
        }
        return sum;
    }
}


import java.util.*;
public class Solution1336C{

    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        String[] vk=in.nextLine().split(" ");
        int V=Integer.parseInt(vk[0]);
        int k=Integer.parseInt(vk[1]);
        int c=0;
        graph g=new graph(V);
        while(c<V-1){
            String[] uv=in.nextLine().split(" ");
            g.addEdge(Integer.parseInt(uv[0])-1,Integer.parseInt(uv[1])-1);
            c++;
        }
        System.out.println(g.bfs(k));
    }
}
class graph{
    int V;
    ArrayList<Integer>[] adj;
    int[][] dist_out;
    public graph(int V){
        this.V=V;
        adj=new ArrayList[V];
        for(int i=0;i<V;i++){
            adj[i]=new ArrayList<Integer>();
        }
        dist_out=new int[V][3];
    }
    public void addEdge(int u, int v){
        adj[u].add(v);
        adj[v].add(u);
    }
    public int bfs(int k){
        Queue<Integer> q=new LinkedList<>();
        q.add(0);

        int l=0;
        boolean[] visited=new boolean[V];
        visited[0]=true;
        while(!q.isEmpty()){
            int sz=q.size();
            while(sz-->0){
                int node=q.poll();
                // System.out.println("node= "+node+" lev="+l);
                for(int v:adj[node]){
                    // System.out.println("edge to "+v);
                    if(!visited[v]){
                        dist_out[node][1]++;
                        visited[v]=true;
                        q.add(v);
                    }
                }
                dist_out[node][0]=l;
                dist_out[node][2]=dist_out[node][0]-dist_out[node][1];
            }

            l++;
        }
        Arrays.sort(dist_out, (a,b)->a[2]-b[2]);
        int c=0;
        int i=V-1;
        int sum=0;
        // System.out.println(Arrays.deepToString(dist_out));
        while(c<k){
            sum+=dist_out[i][2];
            i--;
            c++;
        }
        return sum;
    }
}


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

public class A1336 {
    static ArrayList<Integer>[] gr, hg;
    static int parent[] = new int[212345];
    static int size[] = new int[212345];
    static int height__tree[] = new int[212345];
    static boolean blacklisted[] = new boolean[212345];
    static int max_height = 0;
    static long solve(int v){
        long cnt = 1;
        while (v!=1){
            if (!blacklisted[v]) cnt++;
            v = parent[v];
        }
        return cnt;
    }

    static int dfs2(int cur, int pa,int height){
        int sz=1;
        for (int v:gr[cur]){
            if (v == pa) continue;
            sz += dfs2(v, cur, height + 1);
        }
        size[cur] = sz;
        parent[cur] = height;
        height__tree[cur] = size[cur] - height;
        return size[cur];
    }

    static class cmp implements Comparator<Integer>{
        public int compare(Integer a, Integer b){
            return size[a]-size[b];
        }
    }
    static class Pair{
        int in1;
        int in2;
        public Pair(){

        }
        public Pair(int in1, int in2){
            this.in1 = in1;
            this.in2 = in2;
        }
    };
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in[] = br.readLine().trim().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);
        gr = new ArrayList[n+1];
        hg = new ArrayList[n+1];
        for (int i=0;i<=n;++i){
            gr[i] = new ArrayList<>();
            hg[i] = new ArrayList<>();
        }
        Arrays.fill(parent, 0);
        Arrays.fill(blacklisted, false);
        Arrays.fill(size, 0);
        max_height = 0;
        for (int i=0;i<n-1;++i) {
            in = br.readLine().trim().split(" ");
            int u = Integer.parseInt(in[0]);
            int v = Integer.parseInt(in[1]);
            gr[u].add(v);
            gr[v].add(u);
        }
        dfs2(1,0, 1);
        height__tree[0] = Integer.MAX_VALUE;
        List<Pair>p = new ArrayList<>();
        for (int i=1;i<=n;++i){
            p.add(new Pair(height__tree[i], i));
            //System.out.println(i + " " + height__tree[i]);
        }
        Collections.sort(p, new Comparator<Pair>() {
            @Override public int compare(Pair p1, Pair p2)
            {
                return p2.in1 - p1.in1;
            }
        });
        int res = n - k;
        int ans = 0;
        for (Pair pcur:p){
            if (res == 0)
                break;
            // System.out.println(pcur.in2 + " " + parent[pcur.in2]);
            ans += height__tree[pcur.in2];
            --res;
        }
        System.out.println(ans);
    }
}
/**
 * 1 2
 * 2 3
 * 3 4
 * 2 5
 * 1 6
 * 6 7
 * 7 8
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class A1336 {
    static ArrayList<Integer>[] gr, hg;
    static int parent[] = new int[212345];
    static int size[] = new int[212345];
    static boolean blacklisted[] = new boolean[212345];
    static int max_height = 0;
    static int dfs1(int cur, int pa,int height){
        max_height = Math.max(max_height, height);
        hg[height].add(cur);
        int sz=1;
        for (int v:gr[cur]){
            if (v == pa) continue;
            parent[v] = cur;
            sz += dfs1(v, cur, height + 1);
        }
        size[cur] = sz;
        return size[cur];
    }
    static int solve(int v){
        int cnt = 1;
        while (v!=1){
            if (!blacklisted[v]) cnt++;
            v = parent[v];
        }
        return cnt;
    }
    static class cmp implements Comparator<Integer>{
        public int compare(Integer a, Integer b){
            return size[a]-size[b];
        }
    }
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in[] = br.readLine().trim().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);
        gr = new ArrayList[n+1];
        hg = new ArrayList[n+1];
        for (int i=0;i<=n;++i){
            gr[i] = new ArrayList<>();
            hg[i] = new ArrayList<>();
        }
        Arrays.fill(parent, 0);
        Arrays.fill(blacklisted, false);
        Arrays.fill(size, 0);
        for (int i=0;i<n-1;++i) {
            in = br.readLine().trim().split(" ");
            int u = Integer.parseInt(in[0]);
            int v = Integer.parseInt(in[1]);
            gr[u].add(v);
            gr[v].add(u);
        }
        dfs1(1, -1, 1);
        for (int i=1;i<=n;++i){
            Collections.sort(hg[i], new cmp());
        }
        for (int i=max_height; i>=1 ; --i){
            for (int cur:hg[i]){
                blacklisted[cur] = true;
                --k;
                if (k<1) break;
            }
            if (k<1) break;
        }
        long ans = 0;
        for (int i=1;i<=n;++i){
            if (blacklisted[i]){
                // System.out.println(i + " " + solve(i));
                ans += solve(i);
            }
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class A1336 {
    static ArrayList<Integer>[] gr, hg;
    static int parent[] = new int[212345];
    static int size[] = new int[212345];
    static boolean blacklisted[] = new boolean[212345];
    static int max_height = 0;
    static int dfs1(int cur, int pa,int height){
        max_height = Math.max(max_height, height);
        hg[height].add(cur);
        int sz=1;
        for (int v:gr[cur]){
            if (v == pa) continue;
            parent[v] = cur;
            sz += dfs1(v, cur, height + 1);
        }
        size[cur] = sz;
        return size[cur];
    }
    static long solve(int v){
        long cnt = 1;
        while (v!=1){
            if (!blacklisted[v]) cnt++;
            v = parent[v];
        }
        return cnt;
    }
    static class cmp implements Comparator<Integer>{
        public int compare(Integer a, Integer b){
            return size[a]-size[b];
        }
    }
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in[] = br.readLine().trim().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);
        gr = new ArrayList[n+1];
        hg = new ArrayList[n+1];
        for (int i=0;i<=n;++i){
            gr[i] = new ArrayList<>();
            hg[i] = new ArrayList<>();
        }
        Arrays.fill(parent, 0);
        Arrays.fill(blacklisted, false);
        Arrays.fill(size, 0);
        max_height = 0;
        for (int i=0;i<n-1;++i) {
            in = br.readLine().trim().split(" ");
            int u = Integer.parseInt(in[0]);
            int v = Integer.parseInt(in[1]);
            gr[u].add(v);
            gr[v].add(u);
        }
        dfs1(1, -1, 1);
        for (int i=1;i<=n;++i){
            Collections.sort(hg[i], new cmp());
        }
        for (int i=max_height; i>=1 ; --i){
            for (int cur:hg[i]){
                blacklisted[cur] = true;
                --k;
                if (k<1) break;
            }
            if (k<1) break;
        }
        long ans = 0;
        for (int i=1;i<=n;++i){
            if (blacklisted[i]){
                // System.out.println(i + " " + solve(i));
                ans += solve(i);
            }
        }
        System.out.println(ans);
    }
}
/**
 * 1 2
 * 2 3
 * 3 4
 * 2 5
 * 1 6
 * 6 7
 * 7 8
 */


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

public class A1336 {
    static ArrayList<Integer>[] gr, hg;
    static int parent[] = new int[212345];
    static int size[] = new int[212345];
    static int height__tree[] = new int[212345];
    static boolean blacklisted[] = new boolean[212345];
    static int max_height = 0;
    static long solve(int v){
        long cnt = 1;
        while (v!=1){
            if (!blacklisted[v]) cnt++;
            v = parent[v];
        }
        return cnt;
    }

    static int dfs2(int cur, int pa,int height){
        int sz=1;
        for (int v:gr[cur]){
            if (v == pa) continue;
            sz += dfs2(v, cur, height + 1);
        }
        size[cur] = sz;
        parent[cur] = height;
        height__tree[cur] = size[cur] - height;
        return size[cur];
    }

    static class cmp implements Comparator<Integer>{
        public int compare(Integer a, Integer b){
            return size[a]-size[b];
        }
    }
    static class Pair{
        int in1;
        int in2;
        public Pair(){

        }
        public Pair(int in1, int in2){
            this.in1 = in1;
            this.in2 = in2;
        }
    };
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in[] = br.readLine().trim().split(" ");
        int n = Integer.parseInt(in[0]);
        int k = Integer.parseInt(in[1]);
        gr = new ArrayList[n+1];
        hg = new ArrayList[n+1];
        for (int i=0;i<=n;++i){
            gr[i] = new ArrayList<>();
            hg[i] = new ArrayList<>();
        }
        Arrays.fill(parent, 0);
        Arrays.fill(blacklisted, false);
        Arrays.fill(size, 0);
        max_height = 0;
        for (int i=0;i<n-1;++i) {
            in = br.readLine().trim().split(" ");
            int u = Integer.parseInt(in[0]);
            int v = Integer.parseInt(in[1]);
            gr[u].add(v);
            gr[v].add(u);
        }
        dfs2(1,0, 1);
        height__tree[0] = Integer.MAX_VALUE;
        List<Pair>p = new ArrayList<>();
        for (int i=1;i<=n;++i){
            p.add(new Pair(height__tree[i], i));
            //System.out.println(i + " " + height__tree[i]);
        }
        Collections.sort(p, new Comparator<Pair>() {
            @Override public int compare(Pair p1, Pair p2)
            {
                return p2.in1 - p1.in1;
            }
        });
        int res = n - k;
        long ans = 0;
        for (Pair pcur:p){
            if (res == 0)
                break;
            // System.out.println(pcur.in2 + " " + parent[pcur.in2]);
            ans += height__tree[pcur.in2];
            --res;
        }
        System.out.println(ans);
    }
}
/**
 * 1 2
 * 2 3
 * 3 4
 * 2 5
 * 1 6
 * 6 7
 * 7 8
 */


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ALinovaAndKingdom solver = new ALinovaAndKingdom();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ALinovaAndKingdom {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int k = in.readInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node();
            }
            for (int i = 0; i < n - 1; i++) {
                Node a = nodes[in.readInt() - 1];
                Node b = nodes[in.readInt() - 1];
                a.next.add(b);
                b.next.add(a);
            }

            dfs(nodes[0], null, 0);
            Arrays.sort(nodes, (a, b) -> -Integer.compare(a.weight(), b.weight()));
            long sum = 0;
            for (int i = 0; i < k; i++) {
                sum += nodes[i].weight();
            }
            out.println(sum);
        }

        public void dfs(Node root, Node p, int d) {
            root.size = 1;
            root.depth = d;
            for (Node node : root.next) {
                if (node == p) {
                    continue;
                }
                dfs(node, root, d + 1);
                root.size += node.size;
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(long c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(long c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Node {
        List<Node> next = new ArrayList<>();
        int depth;
        int size;

        public int weight() {
            return depth - (size - 1);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        ArrayList<Integer>[] tree;
        int[] depth;
        int[] par;
        int[] dfs;
        int[] size;
        int[] tin;
        FenwickTree cnt;
        int timer = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            tin = new int[N];
            tree = new ArrayList[N];
            depth = new int[N];
            dfs = new int[N];
            par = new int[N];
            size = new int[N];
            cnt = new FenwickTree(N);
            for (int i = 0; i < N; i++) {
                tree[i] = new ArrayList<>();
            }
            for (int i = 0; i < N - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                tree[a].add(b);
                tree[b].add(a);
            }
            root(0, 0, 0);
            PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {

                public int compare(Integer integer, Integer t1) {
                    return -Integer.compare(depth[integer] - size[integer], depth[t1] - size[t1]);
                }
            });
            for (int i = 1; i < N; i++) {
                if (size[i] == 0) {
                    queue.add(i);
                }
            }
            long res = 0;
            while (K-- > 0) {
                int next = queue.remove();
                res += depth[next] - size[next];
                cnt.add(next, 1);
                if (cnt.sum(tin[par[next]], tin[par[next]] + size[par[next]]) == size[par[next]]) {
                    queue.add(par[next]);
                }
            }
            out.println(res);
        }

        int root(int n, int p, int d) {
            tin[n] = timer;
            dfs[timer++] = n;
            depth[n] = d;
            par[n] = p;
            for (int ch : tree[n]) {
                if (ch != p) {
                    size[n]++;
                    size[n] += root(ch, n, d + 1);
                }
            }
            return size[n];
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class FenwickTree {
        public int[] BIT;
        public int size = 0;

        public FenwickTree(int N) {
            BIT = new int[N];
            size = N;
        }

        public FenwickTree(int[] arr) {
            size = arr.length;
            BIT = new int[arr.length];
            for (int i = 0; i < size; i++) {
                add(i, arr[i]);
            }
        }

        public void add(int id, int add) {
            for (int i = id; i < size; i |= i + 1) {
                BIT[i] += add;
            }
        }

        public int sum(int l, int r) {
            if (r < l) {
                return 0;
            }
            return sum(r) - sum(l - 1);
        }

        public int sum(int r) {
            if (r < 0 || r >= size) {
                return 0;
            }
            int res = 0;
            for (int i = r; i >= 0; i = ((i) & (i + 1)) - 1) {
                res += BIT[i];
            }
            return res;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        ArrayList<Integer>[] tree;
        int[] depth;
        int[] par;
        int[] dfs;
        int[] size;
        int[] tin;
        FenwickTree cnt;
        int timer = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            tin = new int[N];
            tree = new ArrayList[N];
            depth = new int[N];
            dfs = new int[N];
            par = new int[N];
            size = new int[N];
            cnt = new FenwickTree(N);
            for (int i = 0; i < N; i++) {
                tree[i] = new ArrayList<>();
            }
            for (int i = 0; i < N - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                tree[a].add(b);
                tree[b].add(a);
            }
            root(0, 0, 0);
            PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {

                public int compare(Integer integer, Integer t1) {
                    return -Integer.compare(depth[integer] - size[integer], depth[t1] - size[t1]);
                }
            });
            for (int i = 1; i < N; i++) {
                if (size[i] == 0) {
                    queue.add(i);
                }
            }
            long res = 0;
            while (K-- > 0) {
                int next = queue.remove();
                res += depth[next] - size[next];
                cnt.add(tin[next], 1);
                if (cnt.sum(tin[par[next]], tin[par[next]] + size[par[next]]) == size[par[next]]) {
                    queue.add(par[next]);
                }
            }
            out.println(res);
        }

        int root(int n, int p, int d) {
            tin[n] = timer;
            dfs[timer++] = n;
            depth[n] = d;
            par[n] = p;
            for (int ch : tree[n]) {
                if (ch != p) {
                    size[n]++;
                    size[n] += root(ch, n, d + 1);
                }
            }
            return size[n];
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class FenwickTree {
        public int[] BIT;
        public int size = 0;

        public FenwickTree(int N) {
            BIT = new int[N];
            size = N;
        }

        public FenwickTree(int[] arr) {
            size = arr.length;
            BIT = new int[arr.length];
            for (int i = 0; i < size; i++) {
                add(i, arr[i]);
            }
        }

        public void add(int id, int add) {
            for (int i = id; i < size; i |= i + 1) {
                BIT[i] += add;
            }
        }

        public int sum(int l, int r) {
            if (r < l) {
                return 0;
            }
            return sum(r) - sum(l - 1);
        }

        public int sum(int r) {
            if (r < 0 || r >= size) {
                return 0;
            }
            int res = 0;
            for (int i = r; i >= 0; i = ((i) & (i + 1)) - 1) {
                res += BIT[i];
            }
            return res;
        }

    }
}


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

public class Problem1336A {

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

        @Override
        public int compareTo(Node n){
            if()
            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-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);

    }
}