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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().run(in, out);
        out.close();
    }

    int N;
    int B;
    List<Integer>[] adj;
    void run(FastScanner in, PrintWriter out) {
        // dfs
        // on the way down get dist from S
        // on the way up get dist from B (root), and also max depth
        // at each intersection, if b can reach the intersection from
        // before S can reach the intersection, B can travel to the
        // max depth leaf of the subtree rooted at the intersection

        N = in.nextInt();
        B = in.nextInt();
        bDist = new int[N+1];
        adj = new List[N+1];
        for (int i = 1; i <= N; i++) adj[i] = new ArrayList<>();

        for (int i = 1; i < N; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            adj[u].add(v);
            adj[v].add(u);
        }

        // dfs from B to get distances
        // then dfs from root to get answer
        dfsB(B, -1, 0);
        dfs(1, -1, 0);
        out.println(ans*2);
    }

    int[] bDist;
    void dfsB(int u, int p, int d) {
        bDist[u] = d;
        for (int v : adj[u]) {
            if (v == p) continue;
            dfsB(v, u, d+1);
        }
    }

    int ans = 0;
    // returns max leaf dist
    int dfs(int u, int p, int d) {

        int maxDist = 0;
        for (int v : adj[u]) {
            if (v == p) continue;
            maxDist = Math.max(maxDist, dfs(v, u, d+1));
        }

        // if B can reach here before S can
        if (bDist[u] < d) {
            // b runs here first then goes to the deepest leaf in the
            // subtree
            // s goes from root to leaf
            ans = Math.max(d+maxDist, ans);
        }
        return maxDist+1;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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


/*
ID: mchensd
LANG: JAVA
PROG: TheTagGame
 */

/**
 *
 * @author Michael
 */

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

public class TheTagGame {
    static int m;
    static int[] maxPath;
    static int[] abPath;
    static int pathInd;
    static boolean found = false;
    public static class Tree {
        int V;
        ArrayList<Integer>[] adj;

        public Tree(int V) {
            this.V = V;
            adj = (ArrayList<Integer>[]) new ArrayList[V];
            for (int i=0; i<V; ++i) {
                adj[i] = new ArrayList<>();
            }
        }

        public void addEdge(int v1, int v2) {
            adj[v1].add(v2);
            adj[v2].add(v1);
        }
    }

    public static int dfs(Tree t, int v, int from, int length) {
        if (t.adj[v].size() == 1 && t.adj[v].get(0) == from) return 0;

        for (int n : t.adj[v]) {
            if (n != from) {
                if (!found) {
                    abPath[pathInd] = n;
                    if (n == m) found = true;
                }
                ++pathInd;
                maxPath[v] = Math.max(maxPath[v], 1 + dfs(t, n, v, length+1));
                --pathInd;
            }
        }
        return maxPath[v];
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());

        maxPath = new int[n+1];
        abPath = new int[n+1];
        abPath[0] = 1;
        Tree t = new Tree(n+1);
        for (int i=0; i<n-1; ++i) {
            st = new StringTokenizer(br.readLine());
            t.addEdge(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
        }
        pathInd = 1;
        int max = dfs(t, 1, 1, 0);
//        System.out.println(Arrays.toString(abPath));
//        System.out.println(Arrays.toString(maxPath));
//        System.out.println(max);

        int back = ((pathInd + 1) / 2) - 1;
//        System.out.println(maxPath[2]);
        int longest = maxPath[abPath[pathInd-back]] + pathInd-back;
        pw.println(longest*2);
        pw.close();

    }

}


/*
ID: mchensd
LANG: JAVA
PROG: TheTagGame
 */

/**
 *
 * @author Michael
 */

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

public class TheTagGame {
    static int m;
    static int[] maxPath;
    static int[] abPath;
    static int pathInd, finalPathInd;
    static boolean found = false;
    public static class Tree {
        int V;
        ArrayList<Integer>[] adj;

        public Tree(int V) {
            this.V = V;
            adj = (ArrayList<Integer>[]) new ArrayList[V];
            for (int i=0; i<V; ++i) {
                adj[i] = new ArrayList<>();
            }
        }

        public void addEdge(int v1, int v2) {
            adj[v1].add(v2);
            adj[v2].add(v1);
        }
    }

    public static int dfs(Tree t, int v, int from) {
        if (t.adj[v].size() == 1 && t.adj[v].get(0) == from) return 0;

        for (int n : t.adj[v]) {
            if (n != from) {
                if (!found) {
                    abPath[pathInd] = n;
                    finalPathInd = pathInd;
                    if (n == m) found = true;
                }
                if (!found) {
                    ++pathInd;
                    maxPath[v] = Math.max(maxPath[v], 1 + dfs(t, n, v));
                    --pathInd;
                }
                else maxPath[v] = Math.max(maxPath[v], 1 + dfs(t, n, v));

            }
        }
        return maxPath[v];
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());

        maxPath = new int[n+1];
        abPath = new int[n+1];
        abPath[0] = 1;
        Tree t = new Tree(n+1);
        for (int i=0; i<n-1; ++i) {
            st = new StringTokenizer(br.readLine());
            t.addEdge(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
        }
        pathInd = 1;
        finalPathInd = 1;
        dfs(t, 1, 1);
//        System.out.println(Arrays.toString(abPath));
//        System.out.println(Arrays.toString(maxPath));
//        System.out.println(max);

        int back = ((finalPathInd) / 2) - 1;
//        System.out.println(back);
//        System.out.println(finalPathInd);
//        System.out.println(maxPath[2]);
        int longest = maxPath[abPath[finalPathInd-back]] + finalPathInd-back;
        pw.println(longest*2);
        pw.close();

    }

}


/*
ID: mchensd
LANG: JAVA
PROG: TheTagGame
 */

/**
 *
 * @author Michael
 */

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

public class TheTagGame {
    static int m;
    static int[] maxPath;
    static int[] abPath;
    static int pathInd, finalPathInd;
    static boolean found = false;
    public static class Tree {
        int V;
        ArrayList<Integer>[] adj;

        public Tree(int V) {
            this.V = V;
            adj = (ArrayList<Integer>[]) new ArrayList[V];
            for (int i=0; i<V; ++i) {
                adj[i] = new ArrayList<>();
            }
        }

        public void addEdge(int v1, int v2) {
            adj[v1].add(v2);
            adj[v2].add(v1);
        }
    }

    public static int dfs(Tree t, int v, int from) {
        if (t.adj[v].size() == 1 && t.adj[v].get(0) == from) return 0;

        for (int n : t.adj[v]) {
            if (n != from) {
                if (!found) {
                    abPath[pathInd] = n;
                    finalPathInd = pathInd;
                    if (n == m) found = true;
                }
                if (!found) {
                    ++pathInd;
                    maxPath[v] = Math.max(maxPath[v], 1 + dfs(t, n, v));
                    --pathInd;
                }
                else maxPath[v] = Math.max(maxPath[v], 1 + dfs(t, n, v));

            }
        }
        return maxPath[v];
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken());

        maxPath = new int[n+1];
        abPath = new int[n+1];
        abPath[0] = 1;
        Tree t = new Tree(n+1);
        for (int i=0; i<n-1; ++i) {
            st = new StringTokenizer(br.readLine());
            t.addEdge(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
        }
        pathInd = 1;
        finalPathInd = 1;
        dfs(t, 1, 1);
//        System.out.println(Arrays.toString(abPath));
//        System.out.println(Arrays.toString(maxPath));
//        System.out.println(max);

        int back = ((finalPathInd+1) / 2) - 1;
//        System.out.println(back);
//        System.out.println(finalPathInd);
//        System.out.println(maxPath[2]);
        int longest = maxPath[abPath[finalPathInd-back]] + finalPathInd-back;
        pw.println(longest*2);
        pw.close();

    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    static int N, X;
    static ArrayList<Integer>[] g;
    static int[] level, reach, p;

    static int dfs(int u, int par, int depth) {
	p[u] = par;
	level[u] = depth;
	int max = level[u];
	for (int v : g[u])
	    if (v != par)
		max = Math.max(max, dfs(v, u, depth + 1));
	reach[u] = max;
	return max;
    }

    public static void main(String[] args) throws IOException {
	MyScanner sc = new MyScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	N = sc.nextInt();
	X = sc.nextInt() - 1;
	g = new ArrayList[N];
	for (int i = 0; i < N; i++)
	    g[i] = new ArrayList<>();
	for (int i = 0; i < N - 1; i++) {
	    int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
	    g[u].add(v);
	}
	level = new int[N];
	reach = new int[N];
	p = new int[N];
	dfs(0, -1, 0);
	if (level[X] - level[0] == 1)
	    out.println(reach[X] << 1);
	else {
	    int up = (level[X] - level[0]) >> 1, node = X, max = reach[X];
	    if (((level[X] - level[0]) & 1) == 0)
		up--;
	    while (up-- > 0 && p[node] != -1) {
		node = p[node];
		max = Math.max(max, reach[node]);
	    }
	    out.println(max << 1);
	}
	out.flush();
	out.close();
    }

    static class MyScanner {
	StringTokenizer st;
	BufferedReader br;

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

	public MyScanner(String file) throws IOException {
	    br = new BufferedReader(new FileReader(new File(file)));
	}

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

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

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

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

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    static int N, X;
    static ArrayList<Integer>[] g;
    static int[] level, reach, p;

    static int dfs(int u, int par, int depth) {
	p[u] = par;
	level[u] = depth;
	int max = level[u];
	for (int v : g[u])
	    if (v != par)
		max = Math.max(max, dfs(v, u, depth + 1));
	reach[u] = max;
	return max;
    }

    public static void main(String[] args) throws IOException {
	MyScanner sc = new MyScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	N = sc.nextInt();
	X = sc.nextInt() - 1;
	g = new ArrayList[N];
	for (int i = 0; i < N; i++)
	    g[i] = new ArrayList<>();
	for (int i = 0; i < N - 1; i++) {
	    int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
	    g[u].add(v);
	}
	level = new int[N];
	reach = new int[N];
	p = new int[N];
	dfs(0, -1, 0);
	if (level[X] - level[0] == 1 || ((level[X] - level[0]) & 1) == 0)
	    out.println(reach[X] << 1);
	else {
	    int up = (level[X] - level[0]) >> 1, node = X, max = reach[X];
	    while (up-- > 0 && p[node] != -1) {
		node = p[node];
		max = Math.max(max, reach[node]);
	    }
	    out.println(max << 1);
	}
	out.flush();
	out.close();
    }

    static class MyScanner {
	StringTokenizer st;
	BufferedReader br;

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

	public MyScanner(String file) throws IOException {
	    br = new BufferedReader(new FileReader(new File(file)));
	}

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

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

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

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

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

    static int N, X;
    static ArrayList<Integer>[] g;
    static int[] level, reach, p;

    static int dfs(int u, int par, int depth) {
	p[u] = par;
	level[u] = depth;
	int max = level[u];
	for (int v : g[u])
	    if (v != par)
		max = Math.max(max, dfs(v, u, depth + 1));
	reach[u] = max;
	return max;
    }

    public static void main(String[] args) throws IOException {
	MyScanner sc = new MyScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	N = sc.nextInt();
	X = sc.nextInt() - 1;
	g = new ArrayList[N];
	for (int i = 0; i < N; i++)
	    g[i] = new ArrayList<>();
	for (int i = 0; i < N - 1; i++) {
	    int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
	    g[u].add(v);
	    g[v].add(u);
	}
	level = new int[N];
	reach = new int[N];
	p = new int[N];
	dfs(0, -1, 0);
	if (level[X] - level[0] == 1)
	    out.println(reach[X] << 1);
	else {
	    int up = (level[X] - level[0]) >> 1, node = X, max = reach[X];
	    if (((level[X] - level[0]) & 1) == 0)
		up--;
	    while (up-- > 0 && p[node] != -1) {
		node = p[node];
		max = Math.max(max, reach[node]);
	    }
	    out.println(max << 1);
	}
	out.flush();
	out.close();
    }

    static class MyScanner {
	StringTokenizer st;
	BufferedReader br;

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

	public MyScanner(String file) throws IOException {
	    br = new BufferedReader(new FileReader(new File(file)));
	}

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

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

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

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

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


import java.util.*;

import javax.swing.Painter;

import java.io.*;

public class C {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public static class Pair implements Comparable<Pair> {
		int x;
		int y;
		public Pair(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return x - o.x;
		}

	}

	public static void quickSort(long[] a, int from, int to) {
		if (to - from <= 1) {
			return;
		}
		int i = from;
		int j = to - 1;
		long x = a[from + (new Random()).nextInt(to - from)];
		while (i <= j) {
			while (a[i] < x) {
				i++;
			}
			while (a[j] > x) {
				j--;
			}
			if (i <= j) {
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
				i++;
				j--;
			}
		}
		quickSort(a, from, j + 1);
		quickSort(a, j + 1, to);
	}

	public void dfs(int v, int h, boolean is) {
		used[v] = true;
		if (v == x) {
			is = true;
		}
		if (is) {
			ans = Math.max(ans, h);
		}
		for (int i : a[v]) {
			if (!used[i]) {
				dfs(i, h + 1, is);
			}
		}
	}

	int x;
	ArrayList<Integer>[] a;
	boolean[] used;
	int ans = 0;

	public void solve() throws IOException {
		int n = in.nextInt();
		x = in.nextInt() - 1;
		a = new ArrayList[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = new ArrayList<>();
		}
		used = new boolean[n];
		for (int i = 0; i < a.length - 1; i++) {
			int y = in.nextInt() - 1;
			int z = in.nextInt() - 1;
			a[y].add(z);
			a[z].add(y);
		}
		dfs(0, 0, false);
		System.out.println(2 * ans);
	}

	public void run() throws IOException {
		if (systemIO) {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);
		} else {
			in = new FastScanner(new File("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] arg) throws IOException {
		new C().run();
	}
}


import java.util.*;

import javax.swing.Painter;

import java.io.*;

public class C {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public static class Pair implements Comparable<Pair> {
		int x;
		int y;
		public Pair(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return x - o.x;
		}

	}

	public static void quickSort(long[] a, int from, int to) {
		if (to - from <= 1) {
			return;
		}
		int i = from;
		int j = to - 1;
		long x = a[from + (new Random()).nextInt(to - from)];
		while (i <= j) {
			while (a[i] < x) {
				i++;
			}
			while (a[j] > x) {
				j--;
			}
			if (i <= j) {
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
				i++;
				j--;
			}
		}
		quickSort(a, from, j + 1);
		quickSort(a, j + 1, to);
	}

	public void dfs(int v, int h) {
		used[v] = true;
		d1[v] = h;
		for (int i : a[v]) {
			if (!used[i]) {
				dfs(i, h + 1);
			}
		}
	}

	public void dfs1(int v, int h) {
		used[v] = true;
		ans = Math.max(d1[v], ans);
		for (int i : a[v]) {
			if (!used[i] && h + 1 < d1[i]) {
				dfs1(i, h + 1);
			}
		}
	}

	int x;
	ArrayList<Integer>[] a;
	boolean[] used;
	int[] d1;
	int ans = 0;

	public void solve() throws IOException {
		int n = in.nextInt();
		x = in.nextInt() - 1;
		a = new ArrayList[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = new ArrayList<>();
		}
		d1 = new int[n];
		used = new boolean[n];
		for (int i = 0; i < a.length - 1; i++) {
			int y = in.nextInt() - 1;
			int z = in.nextInt() - 1;
			a[y].add(z);
			a[z].add(y);
		}
		dfs(0, 0);
		used = new boolean[n];
		dfs1(x, 0);
		System.out.println(2 * ans);
	}

	public void run() throws IOException {
		if (systemIO) {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);
		} else {
			in = new FastScanner(new File("input.txt"));
			out = new PrintWriter(new File("output.txt"));
		}
		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] arg) throws IOException {
		new C().run();
	}
}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class M
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		int visit1[]=new int[n+1];
		int visitx[]=new int[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private static void dfs(ArrayList<Integer>[] list,int []d,int[] visit,int s,int l)
	{
		//System.out.println("@@");
		d[s]=l;
		visit[s]++;
		for(int i:list[s])
		{
			if(visit[i] == 0)
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}
	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class M implements Runnable
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new M(),"TESTCLASS",1<<18).start();
	}
	public void run()
	{
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		int visit1[]=new int[n+1];
		int visitx[]=new int[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private void dfs(ArrayList<Integer>[] list,int []d,int[] visit,int s,int l)
	{
		//System.out.println("@@");
		d[s]=l;
		visit[s]++;
		for(int i:list[s])
		{
			if(visit[i] == 0)
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}
	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class M implements Runnable
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new M(),"TESTCLASS",1<<18).start();
	}
	public void run()
	{
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		boolean visit1[]=new boolean[n+1];
		boolean visitx[]=new boolean[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private void dfs(ArrayList<Integer>[] list,int []d,boolean[] visit,int s,int l)
	{
		//System.out.println("@@");
		d[s]=l;
		visit[s]=true;
		for(int i:list[s])
		{
			if(!visit[i])
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}
	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class TestClass //implements Runnable
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{/*
		new Thread(null, new TestClass(),"TESTCLASS",1<<23).start();
	}
	public void run()
	{*/
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		boolean visit1[]=new boolean[n+1];
		boolean visitx[]=new boolean[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private static void dfs(ArrayList<Integer>[] list,int []d,boolean[] visit,int s,int l)
	{
		//System.out.println("@@");
		if(visit[s])
			return;
		d[s]=l;
		visit[s]=true;
		for(int i:list[s])
		{
			if(!visit[i])
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}

	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class TestClass implements Runnable
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new TestClass(),"TESTCLASS",1<<18).start();
	}
	public void run()
	{
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		boolean visit1[]=new boolean[n+1];
		boolean visitx[]=new boolean[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private void dfs(ArrayList<Integer>[] list,int []d,boolean[] visit,int s,int l)
	{
		//System.out.println("@@");
		if(visit[s])
			return;
		d[s]=l;
		visit[s]=true;
		for(int i:list[s])
		{
			if(!visit[i])
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}
	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class TestClass implements Runnable
{
	/*int x,y;
	public TestClass(int x,int y)
	{
		this.x=x;
		this.y=y;
	}*/
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new TestClass(),"TESTCLASS",1<<23).start();
	}
	public void run()
	{
		//Scanner scan=new Scanner(System.in);
		InputReader hb=new InputReader(System.in);
		PrintWriter w=new PrintWriter(System.out);

		int n=hb.nextInt();
		int x=hb.nextInt();

		ArrayList<Integer> list[]=new ArrayList[n+1];
		for(int i=1;i<=n;i++)
			list[i]=new ArrayList<Integer>();

		int d1[]=new int[n+1];
		int dx[]=new int[n+1];

		for(int i=0;i<n-1;i++)
		{
			int u=hb.nextInt();
			int v=hb.nextInt();
			list[u].add(v);
			list[v].add(u);
		}
		boolean visit1[]=new boolean[n+1];
		boolean visitx[]=new boolean[n+1];
		dfs(list,d1,visit1,1,0);
		dfs(list,dx,visitx,x,0);
		int ans=0;
		for(int i=0;i<=n;i++)
		{
			//w.println(d1[i]+" "+dx[i]);
			if(d1[i]>dx[i] && ans<2*d1[i])
				ans=2*d1[i];
		}
		w.print(ans);
		//w.print("DONE");
		w.close();
	}

	private void dfs(ArrayList<Integer>[] list,int []d,boolean[] visit,int s,int l)
	{
		//System.out.println("@@");
		if(visit[s])
			return;
		d[s]=l;
		visit[s]=true;
		for(int i:list[s])
		{
			if(!visit[i])
			{
				dfs(list,d,visit,i,l+1);
			}
		}
	}

	private void shuffle(int[] arr)
	{
		Random ran = new Random();
		for (int i = 0; i < arr.length; i++) {
			int i1 = ran.nextInt(arr.length);
			int i2 = ran.nextInt(arr.length);

			int temp = arr[i1];
			arr[i1] = arr[i2];
			arr[i2] = temp;
		}
	}

	static class DSU
	{
		int parent[];
		int sizeParent[];
		DSU(int n)
		{
			parent=new int[n];
			sizeParent=new int[n];
			Arrays.fill(sizeParent,1);
			for(int i=0;i<n;i++)
				parent[i]=i;
		}

		int find(int x)
		{
			if(x!=parent[x])
				parent[x]=find(parent[x]);
			return parent[x];
		}

		void union(int x,int y)
		{
			x=find(x);
			y=find(y);
			if(sizeParent[x]>=sizeParent[y])
			{
				if(x!=y)
					sizeParent[x]+=sizeParent[y];
				parent[y]=x;
			}
			else
			{
				if(x!=y)
					sizeParent[y]+=sizeParent[x];
				parent[x]=y;
			}
		}
	}

	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

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

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

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

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

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

			return res.toString();
		}

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

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

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

	static class Pair implements Comparable<Pair>
	{
		int a;
		int b;
		String str;
		public Pair(int a,int b)
		{
			this.a=a;
			this.b=b;
			str=min(a,b)+" "+max(a,b);
		}

		public int compareTo(Pair pair)
		{
			if(Integer.compare(a,pair.a)==0)
				return Integer.compare(b,pair.b);

			return Integer.compare(a,pair.a);
		}
	}

}


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

public class Main {
    private static Scanner sc;
    private static Printer pr;
    static long aLong=(long )1e9+7;
    static long Mod=998244353;
    static TreeSet<Integer>[]list;
    static int []distanceX;
    static int []distanceRoot;
    static boolean[]visRoot;
    static boolean[]visX;
    private static void solve() throws IOException {
        //in the name of god
        // you are anything and we are nothing
        int n=sc.nextInt(),x=sc.nextInt();
        list=new TreeSet[n+1];
        distanceRoot=new int[n+1];
        distanceX=new int[n+1];
        for (int i=1;i<=n;++i)
            list[i]=new TreeSet<>();
        for (int i=1;i<=n-1;++i){
            int u=sc.nextInt(),v=sc.nextInt();
            list[u].add(v);
            list[v].add(u);
        }
        visRoot=new boolean[n+1];
        visX=new boolean[n+1];
        dfs_1(1,0);
        dfs_2(x,0);
        int ans=0;
        for (int i=1;i<=n;++i){
            if (distanceRoot[i]>distanceX[i])
                ans=Math.max(distanceRoot[i]<<1,ans);
        }
        pr.println(ans);
    }
    public static  void dfs_1(int src,int lev){
        if (visRoot[src])
            return;
        distanceRoot[src]=lev;
        visRoot[src]=true;
        for (int v:list[src]){
            if (!visRoot[v])
                dfs_1(v,lev+1);
        }
    }
    public static  void dfs_2(int src,int lev){
        if (visX[src])
            return;
        distanceX[src]=lev;
        visX[src]=true;
        for (int v:list[src]){
            if (!visX[v])
                dfs_2(v,lev+1);
        }
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
        // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

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

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

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

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

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

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}


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

public class Main {
    private static Scanner sc;
    private static Printer pr;
    static long aLong=(long )1e9+7;
    static long Mod=998244353;
    static TreeSet<Integer>[]list;
    static int []level;
    static int tNode,tLev;
    private static void solve() throws IOException {
        //in the name of god
        // you are anything and we are nothing
        int n=sc.nextInt(),x=sc.nextInt();
        list=new TreeSet[n+1];
        level=new int[n+1];
        for (int i=1;i<=n;++i)
            list[i]=new TreeSet<>();
        for (int i=1;i<=n-1;++i){
            int u=sc.nextInt(),v=sc.nextInt();
            list[u].add(v);
            list[v].add(u);
        }
        dfs(1,-1);
        tLev=level[x];
        tNode=x;
        targetNode(x);
        pr.println(tLev<<1);
    }
    public static void targetNode(int src){
        for (int v:list[src]){
            if (level[src]<level[v]){
                if (level[v]>tLev){
                    tLev=level[v];
                    tNode=v;
                }
                targetNode(v);
            }
        }
    }
    public static  void dfs(int src,int par){
        for (int v:list[src]){
            if (v!=par){
                level[v]=level[src]+1;
                dfs(v,src);
            }
        }
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
        // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

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

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

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

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

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

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}


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

public class Main {
    private static Scanner sc;
    private static Printer pr;
    static long aLong=(long )1e9+7;
    static long Mod=998244353;
    static TreeSet<Integer>[]list;
    static int []level;
    static ArrayList<Integer>path;
    static boolean checkT=false;
    private static void solve() throws IOException {
        //in the name of god
        // you are anything and we are nothing
        int n=sc.nextInt(),x=sc.nextInt();
        list=new TreeSet[n+1];
        level=new int[n+1];
        path=new ArrayList<>();
        for (int i=1;i<=n;++i)
            list[i]=new TreeSet<>();
        for (int i=1;i<=n-1;++i){
            int u=sc.nextInt(),v=sc.nextInt();
            list[u].add(v);
            list[v].add(u);
        }
        dfs(1,-1);
        //pr.println(Arrays.toString(level));
        findPath(1,-1,x);
        //pr.println(path);
        int ans=0;
        for (int i=0;i<path.size()/2;++i){
            ans=Math.max(ans,2*(i+level[path.get(path.size()-1-i)]));
        }
        pr.println(ans);
    }
    public static void findPath(int src,int par,int x){
        if (src==x) {
            checkT = true;
            path.add(src);
        }
        if (!checkT) {
            for (int v : list[src]) {
                if (v != par ) {
                    findPath(v, src, x);
                }
            }
            if (checkT)
                path.add(src);
        }
    }
    public static  void dfs(int src,int par){
        for (int v:list[src]) {
            if (v != par) {
                dfs(v, src);
                level[src]=Math.max(level[src],level[v]+1);
            }
        }
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
        // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

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

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

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

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

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

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}


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

public class Main {
    private static Scanner sc;
    private static Printer pr;
    static long aLong=(long )1e9+7;
    static long Mod=998244353;
    static TreeSet<Integer>[]list;
    static int []distanceX;
    static int []distanceRoot;
    private static void solve() throws IOException {
        //in the name of god
        // you are anything and we are nothing
        int n=sc.nextInt(),x=sc.nextInt();
        list=new TreeSet[n+1];
        distanceRoot=new int[n+1];
        distanceX=new int[n+1];
        for (int i=1;i<=n;++i)
            list[i]=new TreeSet<>();
        for (int i=1;i<=n-1;++i){
            int u=sc.nextInt(),v=sc.nextInt();
            list[u].add(v);
            list[v].add(u);
        }
        boolean []visRoot=new boolean[n+1];
        boolean []visX=new boolean[n+1];
        dfs(distanceRoot,visRoot,1,0);
        dfs(distanceX,visX,x,0);
        int ans=0;
        for (int i=1;i<=n;++i){
            if (distanceRoot[i]>distanceX[i])
                ans=Math.max(distanceRoot[i]<<1,ans);
        }
        pr.println(ans);
    }
    public static  void dfs(int []distance,boolean []vis,int src,int lev){
        if (vis[src])
            return;
        distance[src]=lev;
        vis[src]=true;
        for (int v:list[src]){
            if (!vis[v])
                dfs(distance,vis,v,lev+1);
        }
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
        // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

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

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

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

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

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

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e5 + 1000;
typedef long long ll;
const int  inf = 1e6;
void read(int  &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;
}
int n,m;

vector <int> vec[maxn];
int dep[maxn],fa[maxn];

int dfs(int cnt,int la)
{
    int Max = 0;
    int siz = vec[cnt].size();

    for(int i=0;i<siz;i++)
    {
        int now  = vec[cnt][i];
        if(now==la)continue;
        dep[now] = dep[cnt]+1;
        Max=max(dfs(now,cnt),Max);
    }
    fa[cnt]=Max;
    return Max+1;
}
bool flag = true;
int vis[maxn];
int path[maxn],tot = 1;
void pdfs(int cnt,int fa,int now )
{
    if(!flag)return ;
    int siz = vec[cnt].size();
    path[now]=cnt;
    //tot++;
    if(cnt==m)
    {
        tot = now;
        flag = false;
        return ;
    }
    for(int i=0;i<siz;i++)
    {
        int now = vec[cnt][i];
        if(fa==now)continue;
        pdfs(now,cnt,now+1);
        if(!flag)return ;
    }
}
int main() {
    memset(dep,0,sizeof(dep));
    memset(fa,0,sizeof(fa));
    read(n),read(m);
    for(int i=0;i<n-1;i++){
        int a,b;read(a),read(b);
        vec[a].push_back(b),vec[b].push_back(a);
    }
    dfs(1,-1);
    pdfs(1,-1,1);
    int ans = 0;
    memset(vis,0,sizeof(vis));
    ///cout<<tot<<endl;
    for(int i=tot,j=1;i;i--,j++)
    {
        vis[j]=1;
        if(!vis[i])ans=max(ans,dep[path[i]]+fa[path[i]]);
    }
    cout<<ans*2<<endl;
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> mp[200001];
int n,x,a,b,ans,f;
int d1[200001],d2[200001];
void dfs(int p,int from,int step,int *d)
{
    if(mp[p].size()==1&&p!=1)
        d[p]=step;
    for(int i=0;i<mp[p].size();i++)
        if(mp[p][i]!=from)
            dfs(mp[p][i],p,step+1,d);
    return;
}
int main()
{
    scanf("%d%d",&n,&x);
    for(int i=0;i<n-1;i++)
    {
        scanf("%d%d",&a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    dfs(1,-1,0,d1);
    dfs(x,-1,0,d2);
    ans=0;
    for(int i=2;i<=n;i++)
        if(mp[i].size()==1&&d1[i]>d2[i])
            ans=max(ans,d1[i]*2);
    printf("%d\n",ans);
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e5 + 1000;
typedef long long ll;
const int  inf = 1e6;
void read(int  &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;
}
int n,m;

vector <int> vec[maxn];
int dep[maxn],fa[maxn];

int dfs(int cnt,int la)
{
    int Max = 0;
    int siz = vec[cnt].size();

    for(int i=0;i<siz;i++)
    {
        int now  = vec[cnt][i];
        if(now==la)continue;
        dep[now] = dep[cnt]+1;
        Max=max(dfs(now,cnt),Max);
    }
    ///fa[cnt]=Max+1;
    return fa[cnt]=Max+1;
}
bool flag = true;
int vis[maxn];
int path[maxn],tot = 1;
void pdfs(int cnt,int fa,int now)
{
    if(!flag)return ;
    int siz = vec[cnt].size();
    path[now]=cnt;
    if(cnt==m)
    {
        tot = now;
        flag = false;
        return ;
    }
    for(int i=0;i<siz;i++)
    {
        int no = vec[cnt][i];
        if(fa==no)continue;
        pdfs(no,cnt,now+1);
        if(!flag)return ;
    }
}
int main() {
    memset(dep,0,sizeof(dep));
    memset(fa,0,sizeof(fa));
    read(n),read(m);
    for(int i=0;i<n-1;i++){
        int a,b;read(a),read(b);
        vec[a].push_back(b),vec[b].push_back(a);
    }
    dfs(1,-1);
    pdfs(1,-1,1);
    int ans = 0;
    memset(vis,0,sizeof(vis));
    ///cout<<tot<<endl;
    for(int i=tot,j=1;i;i--,j++)
    {
        vis[j]=1;
        if(!vis[i])ans=max(ans,dep[path[i]]+fa[path[i]]-1);
    }
    cout<<ans*2<<endl;
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e5 + 1000;
typedef long long ll;
const int  inf = 1e6;
void read(int  &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;
}
int n,m;

vector <int> vec[maxn];
int dep[maxn],fa[maxn];

int dfs(int cnt,int la)
{
    int Max = 0;
    int siz = vec[cnt].size();

    for(int i=0;i<siz;i++)
    {
        int now  = vec[cnt][i];
        if(now==la)continue;
        dep[now] = dep[cnt]+1;
        Max=max(dfs(now,cnt),Max);
    }
    ///fa[cnt]=Max+1;
    return fa[cnt]=Max+1;
}
bool flag = true;
int vis[maxn];
int path[maxn],tot = 2;
void pdfs(int cnt,int fa,int now)
{
    if(!flag)return ;
    int siz = vec[cnt].size();
    if(cnt==m)
    {
        flag = false;
        return ;
    }
    if(!flag)return ;
    for(int i=0;i<siz;i++)
    {

        int no = vec[cnt][i];
        if(fa==no)continue;
        path[tot]=no;
        tot++;
        pdfs(no,cnt,now+1);
        if(!flag)return ;
    }
}
int main() {
    memset(dep,0,sizeof(dep));
    memset(fa,0,sizeof(fa));
    read(n),read(m);
    for(int i=0;i<n-1;i++){
        int a,b;read(a),read(b);
        vec[a].push_back(b),vec[b].push_back(a);
    }
    dfs(1,-1);
    pdfs(1,-1,1);
    int ans = 0;
    path[1]=1;
    memset(vis,0,sizeof(vis));
    ///cout<<tot<<endl;
    for(int i=tot,j=1;i;i--,j++)
    {
        if(!vis[i])ans=max(ans,dep[path[i]]+fa[path[i]]-1);
    }
    cout<<ans*2<<endl;
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e5 + 1000;
typedef long long ll;
const int  inf = 1e6;
void read(int  &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;
}
int n,m;

vector <int> vec[maxn];
int dep[maxn],fa[maxn];

int dfs(int cnt,int la)
{
    int Max = 0;
    int siz = vec[cnt].size();

    for(int i=0;i<siz;i++)
    {
        int now  = vec[cnt][i];
        if(now==la)continue;
        dep[now] = dep[cnt]+1;
        Max=max(dfs(now,cnt),Max);
    }
    fa[cnt]=Max;
    return Max+1;
}
bool flag = true;
int vis[maxn];
int path[maxn],tot = 1;
void pdfs(int cnt,int fa)
{
    int siz = vec[cnt].size();
    if(cnt==m)
    {
        ///printf("((");
        flag = false;
        return ;
    }
    for(int i=0;i<siz;i++)
    {
        path[tot++]=vec[cnt][i];
        int now = vec[cnt][i];
       // cout<<fa<<endl;
        if(fa==now)continue;
        ///printf("&***");
        pdfs(now,cnt);
        if(!flag)return ;
    }
}
int main() {
    memset(dep,0,sizeof(dep));
    memset(fa,0,sizeof(fa));
    read(n),read(m);
    for(int i=0;i<n-1;i++){
        int a,b;read(a),read(b);
        vec[a].push_back(b),vec[b].push_back(a);
    }
    dfs(1,-1);
    pdfs(1,-1);
    int ans = 0;
    memset(vis,0,sizeof(vis));
    for(int i=tot-1,j=1;i;i--,j++)
    {
        vis[j]=1;
        if(!vis[i])ans=max(ans,dep[path[i]]+fa[path[i]]);
    }
    cout<<ans*2<<endl;
    return 0;
}


#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e5 + 1000;
typedef long long ll;
const int  inf = 1e6;
void read(int  &x) {
	char ch; bool flag = 0;
	for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
	for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
	x *= 1 - 2 * flag;
}
int n,m;

vector <int> vec[maxn];
int dep[maxn],fa[maxn];

int dfs(int cnt,int la)
{
    int Max = 0;
    int siz = vec[cnt].size();

    for(int i=0;i<siz;i++)
    {
        int now  = vec[cnt][i];
        if(now==la)continue;
        dep[now] = dep[cnt]+1;
        Max=max(dfs(now,cnt),Max);
    }
    ///fa[cnt]=Max+1;
    return fa[cnt]=Max+1;
}
bool flag = true;
int vis[maxn];
int path[maxn],tot = 1;
void pdfs(int cnt,int fa,int now)
{
    if(!flag)return ;
    int siz = vec[cnt].size();
    //path[now]=cnt;
    if(cnt==m)
    {
        //tot = now;
        flag = false;
        return ;
    }
    for(int i=0;i<siz;i++)
    {

        int no = vec[cnt][i];
        if(fa==no)continue;path[tot]=no;
        tot++;
        pdfs(no,cnt,now+1);
        if(!flag)return ;
    }
}
int main() {
    memset(dep,0,sizeof(dep));
    memset(fa,0,sizeof(fa));
    read(n),read(m);
    for(int i=0;i<n-1;i++){
        int a,b;read(a),read(b);
        vec[a].push_back(b),vec[b].push_back(a);
    }
    dfs(1,-1);
    pdfs(1,-1,1);
    int ans = 0;
    memset(vis,0,sizeof(vis));
    ///cout<<tot<<endl;
    for(int i=tot-1,j=1;i;i--,j++)
    {
        //vis[j]=1;
        if(!vis[i])ans=max(ans,dep[path[i]]+fa[path[i]]-1);
    }
    cout<<ans*2<<endl;
    return 0;
}