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

/* Name of the class has to be "Main" only if the class is public. */
public class codeforces implements Runnable
{
	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);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new codeforces(),"codeforces",1<<26).start();
	}

	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int n = s.nextInt();
		int v = s.nextInt();

		ArrayList<Integer>[] adj = new ArrayList[n + 1];

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

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

			int n1 = s.nextInt();
			int n2 = s.nextInt();

			adj[n1].add(n2);
			adj[n2].add(n1);
		}

		Queue<Integer> q = new LinkedList<Integer>();

		int[] level = new int[n + 1];
		Arrays.fill(level, -1);

		level[1] = 0;
		q.add(1);

		while(!q.isEmpty()) {

			int x = q.poll();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(level[y] == -1) {

					level[y] = level[x] + 1;
					q.add(y);
				}
			}
		}

		int[] level2 = new int[n + 1];
		Arrays.fill(level2, -1);

		level[v] = 0;
		q.add(v);

		while(!q.isEmpty()) {

			int x = q.poll();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(y == 1)
					continue;

				if(level2[y] == -1) {

					level2[y] = level2[x] + 1;
					q.add(y);
				}
			}
		}

		int ans = 0;

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

			if(level2[i] >= 0 && level2[i] <= level[i] && level[i] > ans)
				ans = level[i];
		}

		w.println(ans * 2);

		w.close();
	}

}


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

/* Name of the class has to be "Main" only if the class is public. */
public class codeforces implements Runnable
{
	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);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new codeforces(),"codeforces",1<<26).start();
	}

	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int n = s.nextInt();
		int v = s.nextInt();

		ArrayList<Integer>[] adj = new ArrayList[n + 1];

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

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

			int n1 = s.nextInt();
			int n2 = s.nextInt();

			adj[n1].add(n2);
			adj[n2].add(n1);
		}

		Queue<Integer> q = new LinkedList<Integer>();

		int[] level = new int[n + 1];
		Arrays.fill(level, -1);

		level[1] = 0;
		q.add(1);

		while(!q.isEmpty()) {

			int x = q.peek();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(level[y] == -1) {

					level[y] = level[x] + 1;
					q.add(y);
				}
			}

			q.remove();
		}

		int[] level2 = new int[n + 1];
		Arrays.fill(level2, -1);

		level2[v] = 0;
		q.add(v);

		while(!q.isEmpty()) {

			int x = q.peek();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(y == 1)
					continue;

				if(level2[y] == -1) {

					level2[y] = level2[x] + 1;
					q.add(y);
				}
			}

			q.remove();
		}

		int ans = 0;

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

			if(level2[i] >= 0 && level2[i] < level[i] && level[i] > ans)
				ans = level[i];
		}

		w.println(ans * 2);

		w.close();
	}

}


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

/* Name of the class has to be "Main" only if the class is public. */
public class codeforces implements Runnable
{
	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);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new codeforces(),"codeforces",1<<26).start();
	}

	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int n = s.nextInt();
		int v = s.nextInt();

		ArrayList<Integer>[] adj = new ArrayList[n + 1];

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

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

			int n1 = s.nextInt();
			int n2 = s.nextInt();

			adj[n1].add(n2);
			adj[n2].add(n1);
		}

		Queue<Integer> q = new LinkedList<Integer>();

		int[] level = new int[n + 1];
		Arrays.fill(level, -1);

		level[1] = 0;
		q.add(1);

		while(!q.isEmpty()) {

			int x = q.poll();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(level[y] == -1) {

					level[y] = level[x] + 1;
					q.add(y);
				}
			}
		}

		int[] level2 = new int[n + 1];
		Arrays.fill(level2, -1);

		level2[v] = 0;
		q.add(v);

		while(!q.isEmpty()) {

			int x = q.poll();

			for(int i = 0; i < adj[x].size(); i++) {

				int y = adj[x].get(i);

				if(y == 1)
					continue;

				if(level2[y] == -1) {

					level2[y] = level2[x] + 1;
					q.add(y);
				}
			}
		}

		int ans = 0;

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

			if(level2[i] >= 0 && level2[i] <= level[i] && level[i] > ans)
				ans = level[i];
		}

		w.println(ans * 2);

		w.close();
	}

}


import java.util.*;

public class EducationalRound22C {

    static int ans = -1;
    static int x;
    static List<ArrayList<Integer>> neighbors;
    static int[] maxDepths;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        x = sc.nextInt()-1;
        neighbors = new ArrayList<>();
        maxDepths = new int[n];
        for(int i = 0; i < n; i++){
            neighbors.add(new ArrayList<>());
        }

        for(int i = 0; i < n-1; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            neighbors.get(a).add(b);
            neighbors.get(b).add(a);
        }
        boolean[] visited = new boolean[n];
        fillDepths(0, 0, visited);
        visited = new boolean[n+1];
        findX(0,0 , visited);
        System.out.println(2*ans);
    }

    private static int findX(int id, int depth, boolean[] visited) {
        if(visited[id]){
            return -1;
        }
        visited[id] = true;

        if(id == x){
            ans = Math.max(ans, maxDepths[id]);
            return depth;
        }
        int xDepth = -1;
        for(int neighbor : neighbors.get(id)){
            xDepth = Math.max(xDepth,findX(neighbor, depth+1, visited));
        }
        if(xDepth == -1){
            return -1;
        }

        if(xDepth-depth < depth){
            ans = Math.max(ans, maxDepths[id]);
        }

        return xDepth;
    }

    private static int fillDepths(int id, int depth, boolean[] visited) {
        if(visited[id]){
            return 0;
        }
        visited[id] = true;
        int maxDepth = depth;
        for(int neighbor : neighbors.get(id)){
            maxDepth = Math.max(maxDepth,fillDepths(neighbor, depth+1, visited));
        }
        maxDepths[id] = maxDepth;
        return maxDepth;
    }
}


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

public class EducationalRound22C {

    static int ans = -1;
    static int x;
    static List<ArrayList<Integer>> neighbors;
    static int[] maxDepths;

    public static void main(String[] args) throws Exception {
        int n = readInt();
        x = readInt()-1;
        neighbors = new ArrayList<>();
        maxDepths = new int[n];
        for(int i = 0; i < n; i++){
            neighbors.add(new ArrayList<>());
        }

        for(int i = 0; i < n-1; i++){
            int a = readInt()-1;
            int b = readInt()-1;
            neighbors.get(a).add(b);
            neighbors.get(b).add(a);
        }
        boolean[] visited = new boolean[n];
        fillDepths(0, 0, visited);
        visited = new boolean[n+1];
        findX(0,0 , visited);
        System.out.println(2*ans);
    }

    private static int findX(int id, int depth, boolean[] visited) {
        if(visited[id]){
            return -1;
        }
        visited[id] = true;

        if(id == x){
            ans = Math.max(ans, maxDepths[id]);
            return depth;
        }
        int xDepth = -1;
        for(int neighbor : neighbors.get(id)){
            xDepth = Math.max(xDepth,findX(neighbor, depth+1, visited));
        }
        if(xDepth == -1){
            return -1;
        }

        if(xDepth-depth < depth){
            ans = Math.max(ans, maxDepths[id]);
        }

        return xDepth;
    }

    private static int fillDepths(int id, int depth, boolean[] visited) {
        if(visited[id]){
            return 0;
        }
        visited[id] = true;
        int maxDepth = depth;
        for(int neighbor : neighbors.get(id)){
            maxDepth = Math.max(maxDepth,fillDepths(neighbor, depth+1, visited));
        }
        maxDepths[id] = maxDepth;
        return maxDepth;
    }

    static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st = new StringTokenizer(" ");
    static String readString() throws Exception{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(stdin.readLine());
        }
        return st.nextToken();
    }
    static int readInt() throws Exception {
        return Integer.parseInt(readString());
    }
}


import java.util.*;

public class EducationalRound22C {

    static int ans = -1;
    static int x;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        x = sc.nextInt();
        Map<Integer, Vertex> vertices = new HashMap<>();
        for(int i = 1; i <= n; i++){
            vertices.put(i, new Vertex(i));
        }
        for(int i = 0; i < n-1; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            vertices.get(a).addNeighbor(vertices.get(b));
        }
        boolean[] visited = new boolean[n+1];
        fillDepths(vertices.get(1), 0, visited);
        visited = new boolean[n+1];
        findX(vertices.get(1),0 , visited);
        System.out.println(2*ans);
    }

    private static int findX(Vertex vertex, int depth, boolean[] visited) {
        if(visited[vertex.id]){
            return -1;
        }
        visited[vertex.id] = true;

        if(vertex.id == x){
            ans = Math.max(ans, vertex.maxDepth);
            return depth;
        }
        int xDepth = -1;
        for(Vertex neighbor : vertex.neighbors){
            xDepth = Math.max(xDepth,findX(neighbor, depth+1, visited));
        }
        if(xDepth == -1){
            return -1;
        }

        if(xDepth-depth < depth){
            ans = Math.max(ans, vertex.maxDepth);
        }

        return xDepth;
    }

    private static int fillDepths(Vertex vertex, int depth, boolean[] visited) {
        if(visited[vertex.id]){
            return 0;
        }
        visited[vertex.id] = true;
        int maxDepth = depth;
        for(Vertex neighbor : vertex.neighbors){
            maxDepth = Math.max(maxDepth,fillDepths(neighbor, depth+1, visited));
        }
        vertex.maxDepth = maxDepth;
        return maxDepth;
    }

    static class Vertex{
        int id;
        int maxDepth = 0;
        List<Vertex> neighbors;

        Vertex(int id){
            this.id = id;
            neighbors = new ArrayList<>();
        }

        void addNeighbor(Vertex neighbor){
            this.neighbors.add(neighbor);
            neighbor.neighbors.add(this);
        }
    }
}


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

public class TheTagGame{
    public static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        public FastReader(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 char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char)c;
        }
        public String next() {
            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 interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }

    static ArrayList<Integer> a[];
    static int parent[];
    static int height[];
    static int leaf[];
    static int dx[];

    static int dfs(int i, int p, int h)
    {
    	parent[i] = p;
    	height[i] = h;

    	int max = 0;

    	for(int j : a[i])
    	{
    		if(j == p)
    		{
    			continue;
    		}

    		int dis = dfs(j , i , h + 1);
    		if(dis > max)
    		{
    			max = dis;
    		}
    	}

    	leaf[i] = max;
    	return max + 1;
    }

    static void distance_from_x(int x, int distance)
    {
    	dx[x] = distance;

    	if(parent[x] == 0)
    	{
    		return;
    	}
    	else
    	{
    		distance_from_x(parent[x], distance + 1);
    	}
    }
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader sc = new FastReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);

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

        a = new ArrayList[n];
        parent = new int[n];
        height = new int[n];
        leaf = new int[n];
        dx = new int[n];

        Arrays.fill(dx, n + 1);

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

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

        	a[u].add(v);
        	a[v].add(u);
        }

        dfs(0, 0, 0);

        x = x - 1;
        distance_from_x(x, 0);

        /*for(int i = 0; i < n; i++)
        {
        	w.print(parent[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(height[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(leaf[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(dx[i]+" ");
        }
        w.println();*/
        int ans = 0, temp = 0;

        for(int i = 0; i < n; i++)
        {
        	if(height[i] > dx[i])
        	{
        		temp = height[i] + leaf[i];
        	}
        	ans = Math.max(ans, temp);
        }

        w.println(ans*2);
        w.close();
    }
}


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

public class TheTagGame{
    public static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        public FastReader(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 char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char)c;
        }
        public String next() {
            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 interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }

    static ArrayList<Integer> a[];
    static int parent[];
    static int height[];
    static int leaf[];
    static int dx[];

    static int dfs(int i, int p, int h)
    {
    	parent[i] = p;
    	height[i] = h;

    	int max = 0;

    	for(int j : a[i])
    	{
    		if(j == p)
    		{
    			continue;
    		}

    		int dis = dfs(j , i , h + 1);
    		if(dis > max)
    		{
    			max = dis;
    		}
    	}

    	leaf[i] = max;
    	return max + 1;
    }

    static void distance_from_x(int x, int distance)
    {
    	dx[x] = distance;

    	if(parent[x] == 0)
    	{
    		return;
    	}
    	else
    	{
    		distance_from_x(parent[x], distance + 1);
    	}
    }
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader sc = new FastReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);

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

        a = new ArrayList[n];
        parent = new int[n];
        height = new int[n];
        leaf = new int[n];
        dx = new int[n];

        Arrays.fill(dx, n + 1);

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

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

        	a[u].add(v);
        	a[v].add(u);
        }

        dfs(0, 0, 0);

        distance_from_x(x, 0);

        /*for(int i = 0; i < n; i++)
        {
        	w.print(parent[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(height[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(leaf[i]+" ");
        }
        w.println();

        for(int i = 0; i < n; i++)
        {
        	w.print(dx[i]+" ");
        }
        w.println();*/
        int ans = 0, temp = 0;

        for(int i = 0; i < n; i++)
        {
        	if(height[i] > dx[i])
        	{
        		temp = height[i] + leaf[i];
        	}
        	ans = Math.max(ans, temp);
        }

        w.println(ans*2);
        w.close();
    }
}


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

public final class tag_game
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[][] al,level;
	static int[] a,b,cnt;

	static void dfs(int u,int dim,int p,int curr)
	{
		level[dim][u]=curr;

		for(int x:al[u])
		{
			if(x!=p)
			{
				dfs(x,dim,u,curr+1);
			}
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),x=sc.nextInt()-1;cnt=new int[n];al=new int[n][];a=new int[n];b=new int[n];

		for(int i=1;i<n;i++)
		{
			a[i]=sc.nextInt()-1;b[i]=sc.nextInt()-1;

			cnt[a[i]]++;cnt[b[i]]++;
		}

		for(int i=0;i<n;i++)
		{
			al[i]=new int[cnt[i]];cnt[i]=0;
		}

		level=new int[2][n];

		for(int i=1;i<n;i++)
		{
			int u=a[i],v=b[i];

			al[u][cnt[u]++]=v;al[v][cnt[v]++]=u;
		}

		dfs(0,0,-1,0);dfs(x,1,-1,0);int max=0;

		for(int i=0;i<n;i++)
		{
			if(level[1][i]<=level[0][i])
			{
				max=Math.max(max,level[0][i]*2);
			}
		}

		out.println(max);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

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

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


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

public final class tag_game
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[][] al,level;
	static int[] a,b,cnt;

	static void dfs(int u,int dim,int p,int curr)
	{
		level[dim][u]=curr;

		for(int x:al[u])
		{
			if(x!=p)
			{
				dfs(x,dim,u,curr+1);
			}
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),x=sc.nextInt()-1;cnt=new int[n];al=new int[n][];a=new int[n];b=new int[n];

		for(int i=1;i<n;i++)
		{
			a[i]=sc.nextInt()-1;b[i]=sc.nextInt()-1;

			cnt[a[i]]++;cnt[b[i]]++;
		}

		for(int i=0;i<n;i++)
		{
			al[i]=new int[cnt[i]];cnt[i]=0;
		}

		level=new int[2][n];

		for(int i=1;i<n;i++)
		{
			int u=a[i],v=b[i];

			al[u][cnt[u]++]=v;al[v][cnt[v]++]=u;
		}

		dfs(0,0,-1,0);dfs(x,1,-1,0);int max=0;

		for(int i=0;i<n;i++)
		{
			max=Math.max(max,level[0][i]*2);
		}

		out.println(max);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

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

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


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

public final class tag_game
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static int[][] al,level;
	static int[] a,b,cnt;

	static void dfs(int u,int dim,int p,int curr)
	{
		level[dim][u]=curr;

		for(int x:al[u])
		{
			if(x!=p)
			{
				dfs(x,dim,u,curr+1);
			}
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt(),x=sc.nextInt()-1;cnt=new int[n];al=new int[n][];a=new int[n];b=new int[n];

		for(int i=1;i<n;i++)
		{
			a[i]=sc.nextInt()-1;b[i]=sc.nextInt()-1;

			cnt[a[i]]++;cnt[b[i]]++;
		}

		for(int i=0;i<n;i++)
		{
			al[i]=new int[cnt[i]];cnt[i]=0;
		}

		level=new int[2][n];

		for(int i=1;i<n;i++)
		{
			int u=a[i],v=b[i];

			al[u][cnt[u]++]=v;al[v][cnt[v]++]=u;
		}

		dfs(0,0,-1,0);dfs(x,1,-1,0);int max=0;

		for(int i=0;i<n;i++)
		{
			if(level[1][i]<level[0][i])
			{
				max=Math.max(max,level[0][i]*2);
			}
		}

		out.println(max);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

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

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


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

public class Edu22_C {
	static ArrayList<Integer>[] adjList;
	public static void main(String[] args) throws IOException {
		BufferedInputStream bis = new BufferedInputStream(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(bis));
		PrintWriter out = new PrintWriter(System.out);
		String line;
		StringTokenizer st;
		while ((line = br.readLine()) != null && !line.equals("")) {
			st = new StringTokenizer(line);
			int nodes = Integer.parseInt(st.nextToken());
			int bob = Integer.parseInt(st.nextToken()) - 1;
			adjList = new ArrayList[nodes];
			for (int i = 0; i < adjList.length; i++) {
				adjList[i] = new ArrayList<Integer>();
			}
			for (int i = 0;i < nodes - 1;i++) {
				st = new StringTokenizer(br.readLine());
				int start = Integer.parseInt(st.nextToken()) - 1;
				int end = Integer.parseInt(st.nextToken()) - 1;
				adjList[start].add(end);
				adjList[end].add(start);
			}
			int [] aliceTimes = new int[nodes];
			int [] bobTimes = new int[nodes];
			for (int i = 0;i < nodes;i++) {
				aliceTimes[i] = bobTimes[i] = -2;
			}
			aliceTimes[0] = 0;
			bobTimes[bob] = -1;
			doBFS(0, aliceTimes);
			doBFS(bob, bobTimes);
			int ans = 0;
			for (int i = 0;i < nodes;i++) {
				if (aliceTimes[i] - bobTimes[i] > 1)
					ans = Math.max(ans, aliceTimes[i]);
			}
			out.println(ans);
		}
		out.close();
	}
	public static void doBFS(int startNode, int []times) {
		ArrayList<Integer> currLevel = new ArrayList<Integer>();
		ArrayList<Integer> nextLevel = new ArrayList<Integer>();
		currLevel.add(startNode);
		while (!currLevel.isEmpty()) {
			for (int currNode:currLevel) {
				for (int nextNode:adjList[currNode]) {
					if (times[nextNode] == -2) {
						times[nextNode] = times[currNode] + 2;
						nextLevel.add(nextNode);
					}
				}
			}
			currLevel = nextLevel;
			nextLevel = new ArrayList<Integer>();
		}
	}
}


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

public class Edu22_C {
	static ArrayList<Integer>[] adjList;
	static int bob;
	static final int NINF = -1 * (1<<20);
	public static void main(String[] args) throws IOException {
		BufferedInputStream bis = new BufferedInputStream(System.in);
		//bis = new BufferedInputStream(new FileInputStream("C.in"));
		BufferedReader br = new BufferedReader(new InputStreamReader(bis));
		PrintWriter out = new PrintWriter(System.out);
		//out = new PrintWriter("C-mysol.txt");
		String line;
		StringTokenizer st;
		while ((line = br.readLine()) != null && !line.equals("")) {
			st = new StringTokenizer(line);
			int nodes = Integer.parseInt(st.nextToken());
			bob = Integer.parseInt(st.nextToken()) - 1;
			adjList = new ArrayList[nodes];
			for (int i = 0; i < adjList.length; i++) {
				adjList[i] = new ArrayList<Integer>();
			}
			for (int i = 0;i < nodes - 1;i++) {
				st = new StringTokenizer(br.readLine());
				int start = Integer.parseInt(st.nextToken()) - 1;
				int end = Integer.parseInt(st.nextToken()) - 1;
				adjList[start].add(end);
				adjList[end].add(start);
			}
			int [] aliceTimes = new int[nodes];
			int [] bobTimes = new int[nodes];
			for (int i = 0;i < nodes;i++) {
				aliceTimes[i] = bobTimes[i] = -2;
			}
			aliceTimes[0] = 0;
			bobTimes[bob] = -1;
			doBFS(0, aliceTimes);
			doBFS(bob, bobTimes);
			int ans = 0;
			for (int i = 0;i < nodes;i++) {
				if (bobTimes[i] < aliceTimes[i])
					ans = Math.max(ans, aliceTimes[i]);
			}
			out.println(ans);
		}
		out.close();
	}
	public static void doBFS(int startNode, int []times) {
		ArrayList<Integer> currLevel = new ArrayList<Integer>();
		ArrayList<Integer> nextLevel = new ArrayList<Integer>();
		currLevel.add(startNode);
		while (!currLevel.isEmpty()) {
			for (int currNode:currLevel) {
				for (int nextNode:adjList[currNode]) {
					if (times[nextNode] == -2) {
						times[nextNode] = times[currNode] + 2;
						nextLevel.add(nextNode);
					}
				}
			}
			currLevel = nextLevel;
			nextLevel = new ArrayList<Integer>();
		}
	}
}


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

public class Edu22_C {
	static ArrayList<Integer>[] adjList;
	public static void main(String[] args) throws IOException {
		BufferedInputStream bis = new BufferedInputStream(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(bis));
		PrintWriter out = new PrintWriter(System.out);
		String line;
		StringTokenizer st;
		while ((line = br.readLine()) != null && !line.equals("")) {
			st = new StringTokenizer(line);
			int nodes = Integer.parseInt(st.nextToken());
			int bob = Integer.parseInt(st.nextToken());
			adjList = new ArrayList[nodes];
			for (int i = 0; i < adjList.length; i++) {
				adjList[i] = new ArrayList<Integer>();
			}
			for (int i = 0;i < nodes - 1;i++) {
				st = new StringTokenizer(br.readLine());
				int start = Integer.parseInt(st.nextToken()) - 1;
				int end = Integer.parseInt(st.nextToken()) - 1;
				adjList[start].add(end);
				adjList[end].add(start);
			}
			out.println(solve(0, -1));
		}
		out.close();
	}
	public static int solve(int curr, int parent) {
		if (adjList[curr].size() != 1)
			return 0;
		int ans = 0;
		for (int i = 0;i < adjList[curr].size();i++) {
			int neb = adjList[curr].get(i);
			if (neb != parent) {
				ans = Math.max(ans, solve(neb, curr));
			}
		}
		return ans + 2;
	}
}


import old.FoolsAndRoads;

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

import static java.lang.Math.abs;
import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int timeIn;
        int timeOut;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex, int fromIndex) {
        if (u.num == v.num) {
            return u;
        }
        int i = Math.min(u.path.size() - 1, fromIndex);
        Node uParent = u;
        while (i >= 0) {
            uParent = numToVertex[u.path.get(i)];
            if (!isAncestor(uParent, v)) {
                return getCommonNode(uParent, v, numToVertex, i);
            }
            i--;
        }
        return uParent;

    }

    private static int buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int time) {
        node.timeIn = time++;
        List<Integer> connected = graph.get(node.num);
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                time = buildTree(vertex, graph, visited, path, numToVertex, time);
            }
        }
        path.remove(path.size() - 1);
        node.timeOut = time++;
        return time;
    }

    private static Node createVertex(List<Integer> path, Integer num) {
        int i = 1;
        List<Integer> newPath = new ArrayList<>();
        while (i <= path.size()) {
            newPath.add(path.get(path.size() - i));
            i *= 2;
        }

        return new Node(num, newPath, path.size());
    }

    private static boolean isAncestor(Node u, Node v) {
        return (u.timeIn < v.timeIn && v.timeOut < u.timeOut);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(edges.keySet().iterator().next(), new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, 0);

        Node xNode = numToVertex[x];
        int best = xNode.depth * 2;
        for (int i = 2; i < numToVertex.length; i++) {
            Node node = numToVertex[i];
            if (i != x && node.children.isEmpty()) {
                Node commonNode = getCommonNode(xNode, node, numToVertex);

                if (commonNode.depth > xNode.depth - commonNode.depth) {
                    best = max(best, node.depth * 2);
                }
            }

        }
        out.println(best);

        out.close();
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex) {
        if (Math.min(u.depth, v.depth) == 0) {
            return numToVertex[1];
        }

        Node commonNode;
        if (isAncestor(v, u)) {
            commonNode = v;
        } else if (isAncestor(u, v)) {
            commonNode = u;
        } else {
            commonNode = getCommonNode(u, v, numToVertex, u.path.size() - 1);
        }
        return commonNode;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int maxLeave;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static int buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int x) {
        List<Integer> connected = graph.get(node.num);
        int res = path.size();
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num, x);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                vertex.maxLeave = buildTree(vertex, graph, visited, path, numToVertex, x);
                res = max(res, vertex.maxLeave);
            }
        }
        path.remove(path.size() - 1);
        return res;
    }

    private static Node createVertex(List<Integer> path, Integer num, int x) {
        List<Integer> newPath = null;
        if (x == num) {
            newPath = new ArrayList<>(path);
        }

        return new Node(num, newPath, path.size());
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(edges.keySet().iterator().next(), new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, x);

        Node xNode = numToVertex[x];

        int best = (xNode.maxLeave) * 2;
        int i = xNode.path.size() - 1;
        while (i >= 0 && i > xNode.path.size() / 2) {
            Node node = numToVertex[xNode.path.get(i)];
            best = max(best, (node.maxLeave) * 2);
            i--;
        }
        out.println(best);

        out.close();
    }

    private static int findMaxLeave(Integer v, Node[] numToVertex, int depth) {
        int res = depth;
        for (Integer child : numToVertex[v].children) {
            res = max(res, findMaxLeave(child, numToVertex, depth + 1));
        }
        return res;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int timeIn;
        int timeOut;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex, int fromIndex) {
        if (u.num == v.num) {
            return u;
        }
        int i = Math.min(u.path.size() - 1, fromIndex);
        Node uParent = u;
        while (i >= 0) {
            uParent = numToVertex[u.path.get(i)];
            if (!isAncestor(uParent, v)) {
                return getCommonNode(uParent, v, numToVertex, i);
            }
            i--;
        }
        return uParent;

    }

    private static int buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int time) {
        node.timeIn = time++;
        List<Integer> connected = graph.get(node.num);
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                time = buildTree(vertex, graph, visited, path, numToVertex, time);
            }
        }
        path.remove(path.size() - 1);
        node.timeOut = time++;
        return time;
    }

    private static Node createVertex(List<Integer> path, Integer num) {
        int i = 1;
        List<Integer> newPath = new ArrayList<>();
        while (i <= path.size()) {
            newPath.add(path.get(path.size() - i));
            i *= 2;
        }

        return new Node(num, newPath, path.size());
    }

    private static boolean isAncestor(Node u, Node v) {
        return (u.timeIn < v.timeIn && v.timeOut < u.timeOut);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(edges.keySet().iterator().next(), new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, 0);

        Node xNode = numToVertex[x];
        int best = xNode.depth * 2;
        for (int i = 2; i < numToVertex.length; i++) {
            Node node = numToVertex[i];
            if (i != x && node.children.isEmpty()) {
                Node commonNode = getCommonNode(xNode, node, numToVertex);

                if (commonNode.depth > xNode.depth - commonNode.depth) {
                    best = max(best, node.depth * 2);
                }
            }

        }
        out.println(best);

        out.close();
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex) {
        if (Math.min(u.depth, v.depth) == 0) {
            return numToVertex[1];
        }

        Node commonNode;
        if (isAncestor(v, u)) {
            commonNode = v;
        } else if (isAncestor(u, v)) {
            commonNode = u;
        } else {
            commonNode = getCommonNode(u, v, numToVertex, u.path.size() - 1);
        }
        return commonNode;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static void buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int x) {
        List<Integer> connected = graph.get(node.num);
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num, x);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                buildTree(vertex, graph, visited, path, numToVertex, x);
            }
        }
        path.remove(path.size() - 1);
    }

    private static Node createVertex(List<Integer> path, Integer num, int x) {
        List<Integer> newPath = null;
        if (x == num) {
            newPath = new ArrayList<>(path);
        }

        return new Node(num, newPath, path.size());
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(edges.keySet().iterator().next(), new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, x);

        Node xNode = numToVertex[x];

        int maxLeave = findMaxLeave(x, numToVertex, 0);
        int best = (maxLeave + xNode.depth) * 2;
        int i = xNode.path.size() - 1;
        while (i >= 0 && i > xNode.path.size() / 2) {
            maxLeave = findMaxLeave(xNode.path.get(i), numToVertex, 0);
            best = max(best, (maxLeave + i) * 2);
            i--;
        }
        out.println(best);

        out.close();
    }

    private static int findMaxLeave(Integer v, Node[] numToVertex, int depth) {
        int res = depth;
        for (Integer child : numToVertex[v].children) {
            res = max(res, findMaxLeave(child, numToVertex, depth + 1));
        }
        return res;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int timeIn;
        int timeOut;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex, int fromIndex) {
        if (u.num == v.num) {
            return u;
        }
        int i = Math.min(u.path.size() - 1, fromIndex);
        Node uParent = u;
        while (i >= 0) {
            uParent = numToVertex[u.path.get(i)];
            if (!isAncestor(uParent, v)) {
                return getCommonNode(uParent, v, numToVertex, i);
            }
            i--;
        }
        return uParent;

    }

    private static int buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int time) {
        node.timeIn = time++;
        List<Integer> connected = graph.get(node.num);
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                time = buildTree(vertex, graph, visited, path, numToVertex, time);
            }
        }
        path.remove(path.size() - 1);
        node.timeOut = time++;
        return time;
    }

    private static Node createVertex(List<Integer> path, Integer num) {
        int i = 1;
        List<Integer> newPath = new ArrayList<>();
        while (i <= path.size()) {
            newPath.add(path.get(path.size() - i));
            i *= 2;
        }

        return new Node(num, newPath, path.size());
    }

    private static boolean isAncestor(Node u, Node v) {
        return (u.timeIn < v.timeIn && v.timeOut < u.timeOut);
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(edges.keySet().iterator().next(), new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, 0);

        Node xNode = numToVertex[x];
        int best = xNode.depth * 2;
        for (int i = 2; i < numToVertex.length; i++) {
            Node node = numToVertex[i];
            if (i != x && node.children.isEmpty() && node.depth * 2 > best) {
                Node commonNode = getCommonNode(xNode, node, numToVertex);

                if (commonNode.depth > xNode.depth - commonNode.depth) {
                    best = max(best, node.depth * 2);
                }
            }

        }
        out.println(best);

        out.close();
    }

    private static Node getCommonNode(Node u, Node v, Node[] numToVertex) {
        if (Math.min(u.depth, v.depth) == 0) {
            return numToVertex[1];
        }

        Node commonNode;
        if (isAncestor(v, u)) {
            commonNode = v;
        } else if (isAncestor(u, v)) {
            commonNode = u;
        } else {
            commonNode = getCommonNode(u, v, numToVertex, u.path.size() - 1);
        }
        return commonNode;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int maxLeave;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static int buildTree(Node node, List<Integer>[] graph, int[] visited, List<Integer> path, Node[] numToVertex, int x) {
        List<Integer> connected = graph[node.num];
        int res = path.size();
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num, x);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                vertex.maxLeave = buildTree(vertex, graph, visited, path, numToVertex, x);
                res = max(res, vertex.maxLeave);
            }
        }
        path.remove(path.size() - 1);
        return res;
    }

    private static Node createVertex(List<Integer> path, Integer num, int x) {
        List<Integer> newPath = null;
        if (x == num) {
            newPath = new ArrayList<>(path);
        }

        return new Node(num, newPath, path.size());
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        List<Integer>[] edges = new List[n + 1];
        for (int i = 1; i <= n; i++) {
            edges[i] = new ArrayList<>();
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges[u].add(v);
            edges[v].add(u);
        }

        Node root = new Node(1, new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, x);

        Node xNode = numToVertex[x];

        int best = xNode.maxLeave * 2;
        int i = xNode.path.size() - 1;
        while (i >= 0 && i > xNode.path.size() / 2) {
            Node node = numToVertex[xNode.path.get(i)];
            best = max(best, node.maxLeave * 2);
            i--;
        }
        out.println(best);

        out.close();
    }

    private static int findMaxLeave(Integer v, Node[] numToVertex, int depth) {
        int res = depth;
        for (Integer child : numToVertex[v].children) {
            res = max(res, findMaxLeave(child, numToVertex, depth + 1));
        }
        return res;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


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

import static java.lang.Math.max;

/**
 * Created by Katushka on 11.03.2020.
 */
public class C {
    static int[] readArray(int size, InputReader in) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt();
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    private static class Node {
        int num;
        List<Integer> children = new ArrayList<>();
        List<Integer> path;
        private final int depth;
        int maxLeave;

        public Node(int num, List<Integer> path, int depth) {
            this.num = num;
            this.path = path;
            this.depth = depth;
        }
    }

    private static int buildTree(Node node, Map<Integer, List<Integer>> graph, int[] visited, List<Integer> path, Node[] numToVertex, int x) {
        List<Integer> connected = graph.get(node.num);
        int res = path.size();
        path.add(node.num);
        for (Integer num : connected) {
            if (visited[num] == 0) {
                visited[num] = 1;
                Node vertex = createVertex(path, num, x);
                numToVertex[num] = vertex;
                node.children.add(vertex.num);
                vertex.maxLeave = buildTree(vertex, graph, visited, path, numToVertex, x);
                res = max(res, vertex.maxLeave);
            }
        }
        path.remove(path.size() - 1);
        return res;
    }

    private static Node createVertex(List<Integer> path, Integer num, int x) {
        List<Integer> newPath = null;
        if (x == num) {
            newPath = new ArrayList<>(path);
        }

        return new Node(num, newPath, path.size());
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

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

        Map<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            edges.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            edges.get(u).add(v);
            edges.get(v).add(u);
        }

        Node root = new Node(1, new ArrayList<>(), 0);
        int[] visited = new int[n + 1];
        visited[root.num] = 1;
        List<Integer> path = new ArrayList<>();
        Node[] numToVertex = new Node[n + 1];
        numToVertex[root.num] = root;
        buildTree(root, edges, visited, path, numToVertex, x);

        Node xNode = numToVertex[x];

        int best = xNode.maxLeave * 2;
        int i = xNode.path.size() - 1;
        while (i >= 0 && i > xNode.path.size() / 2) {
            Node node = numToVertex[xNode.path.get(i)];
            best = max(best, node.maxLeave * 2);
            i--;
        }
        out.println(best);

        out.close();
    }

    private static int findMaxLeave(Integer v, Node[] numToVertex, int depth) {
        int res = depth;
        for (Integer child : numToVertex[v].children) {
            res = max(res, findMaxLeave(child, numToVertex, depth + 1));
        }
        return res;
    }

    private static void outputArray(int[] ans, PrintWriter out) {
        StringBuilder str = new StringBuilder();
        for (int an : ans) {
            str.append(an).append(" ");
        }
        out.println(str);
    }

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

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

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

        public String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


import java.util.*;
import java.io.*;
public class C813 {
	public static void main(String args[])throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer str = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(str.nextToken());
		int x = Integer.parseInt(str.nextToken());
		Node graph[] = new Node[n];
		for(int i=0; i<n; i++) {
			graph[i] = new Node(i);
		}
		for(int i=0; i<n-1; i++) {
			str = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(str.nextToken()) -1;
			int v = Integer.parseInt(str.nextToken()) -1;
			graph[u].children.add(graph[v]);
			graph[v].children.add(graph[u]);
		}
		Integer distanceFromAlice[] = bfs(graph[0], graph);
		for(Node child:graph) {
			child.color = 0;
		}
		Integer distanceFromBob[] = bfs(graph[x-1], graph);
		//System.out.println(Arrays.deepToString(distanceFromAlice));
		//System.out.println(Arrays.deepToString(distanceFromBob));
		int ans =0;
		for(int i=0; i<n; i++) {
			if(distanceFromAlice[i] > distanceFromBob[i]) {
				ans = Math.max(ans, 2*distanceFromAlice[i]);
			}
		}
		out.println(ans);
		out.flush();
	}

	public static Integer[] bfs(Node source, Node[] graph) {
		Queue<Node> list = new LinkedList<>();
		Integer distance[] = new Integer[graph.length];
		list.add(source);
		source.color = 1;
		distance[source.index] = 0;
		while(!list.isEmpty()) {
			Node node = list.poll();
			for(Node child: node.children) {
				if(child.color == 0) {
					child.color =1;
					list.add(child);
					distance[child.index] = distance[node.index] + 1;
				}
			}
		}
		return distance;
	}
}

class Node{
	ArrayList<Node> children;
	int color;
	int index;
	public Node(int index) {
		children = new ArrayList<>();
		color = 0;
		this.index = index;
	}
}


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

public class C813_DFS {
	public static void main(String args[]) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer str = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(str.nextToken());
		int x = Integer.parseInt(str.nextToken());
		Nodes graph[] = new Nodes[n];
		int distanceAlice[] = new int[n];
		int distanceBob[] = new int[n];
		for(int i=0; i<n; i++) {
			graph[i] = new Nodes(i);
		}
		for(int i=0; i<n-1; i++) {
			str = new StringTokenizer(br.readLine());
			int v = Integer.parseInt(str.nextToken()) -1;
			int u = Integer.parseInt(str.nextToken()) -1;
			graph[v].children.add(graph[u]);
			graph[u].children.add(graph[v]);
		}
		dfs(graph[0], distanceAlice);
		for(int i=0; i<n; i++) {
			graph[i].color = 0;
		}
		dfs(graph[x-1], distanceBob);
		int max =0;
		for(int i=0; i<n; i++) {
			if(distanceAlice[i] > distanceBob[i]) {
				max = Math.max(distanceAlice[i]*2, max);
			}
		}
		out.println(max);
		out.flush();
	}

	public static void dfs(Nodes source, int distance[]) {
		if(source == null) {
			return;
		}
		source.color = 1;
		for(Nodes child:source.children) {
			if(child.color ==0) {
				child.color = 1;
				distance[child.index] = distance[source.index] + 1;
				dfs(child, distance);
			}
		}
	}
}

class Nodes{
	int color;
	ArrayList<Nodes> children;
	int index;

	public Nodes(int index) {
		color = 0;
		children = new ArrayList<>();
		this.index =index;
	}
}


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

public class Main{
	/*
	 * use Integer for sorting
	 * avoid object comparison
	 * NEVER APPEND A STRING -> APPEND char by char
	 * Always use TreeSet instead of HashSet
	 *
	 */
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;

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

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

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

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

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

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

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long) (1e9+7);
	static long cf = 998244353;
    static final long MAX = (long) 1e8;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static long[] fac;
    public static int N = 400000+200;
    public static int x = 0;
    public static boolean[] visited;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = 1;
		edges = new ArrayList[n+1];
		for(int i=0;i<=n;++i) edges[i] = new ArrayList<>();
		for(int i=1;i<n;++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			edges[u].add(v);
			edges[v].add(u);
		}

		int[] tak = new int[n+1];
		int[] aok = new int[n+1];
		dfs(t,0,tak);
		dfs(a,0,aok);
		long ans = 0;
		for(int i=1;i<=n;++i) {
			if(tak[i] < aok[i]) {
				ans = Math.max(ans,aok[i]);
			}
		}
		out.print(2*(ans-1));
		out.close();
	}
	private static void dfs(int v, int parent, int[] level) {
		level[v] = level[parent] + 1;
		for(int child : edges[v]) {
			if(child != parent) dfs(child,v,level);
		}
	}

}


// editorial approach
import java.util.*;
import java.io.*;

public class Main {
	static final int N = (int)4e5;
	static int n, B, tot, j, k;
	static int[] g, pt, nt, d[];

	static void link(int x, int y) {
		pt[++tot] = y; nt[tot] = g[x]; g[x] = tot;
		pt[++tot] = x; nt[tot] = g[y]; g[y] = tot;
	}

	static void dfs(int x, int fa, int tp) {
		d[tp][x] = d[tp][fa] + 1;
		for (int i = g[x]; i > 0; i = nt[i])
			if (pt[i] != fa) dfs(pt[i], x, tp);
	}

	public static void main(String argv[]) {
		Scanner in = new Scanner(new BufferedInputStream(System.in));
		n = in.nextInt(); B = in.nextInt();
		d = new int[2][n + 10];
		g = new int[n + 10]; pt = new int[2 * n + 10]; nt = new int[2 * n + 10];
		for (int i = 1; i < n; ++i) {
			j = in.nextInt(); k = in.nextInt();
			link(j, k);
		}

		d[0][0] = d[1][0] = -1;
		dfs(1, 0, 0);
		dfs(B, 0, 1);

		int ans = 0;
		for (int i = 1; i <= n; ++i) if (d[1][i] < d[0][i] && d[0][i] > ans) ans = d[0][i];
		System.out.printf("%d\n", ans << 1);
	}
}


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

public class TheTagGame {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        int[][] g;
        int[] depths;
        int[] prev;
        boolean[] visited;
        int x, depth;

        private void dfs(int node, int depth) {
            if (visited[node]) return;
            if (node == x) this.depth = depth;
            visited[node] = true;
            depths[node] = depth;
            for (int neigh: g[node]) {
                if (!visited[neigh]) prev[neigh] = node;
                dfs(neigh, depth + 1);
            }
        }

        private int dfs2(int node, int max) {
            int temp = 0;
            for (int neigh: g[node]) {
                if (depths[neigh] > depths[node]) {
                    temp = Math.max(temp, dfs2(neigh, max + 1));
                }
            }
            return Math.max(max, temp);
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            x = inp.nextInt() - 1;
            visited = new boolean[n];
            prev = new int[n];
            g = graph(inp, n, n - 1, true,true);
            depths = new int[n];

            dfs(0, 0);
            int between = depth - 1;
            int res = (between >> 1) << 1;
            if ((between & 1) == 1) res += 4;
            else res += 2;
            int i = between >> 1;
            while (i-- > 0) x = prev[x];
            res += dfs2(x, 0) << 1;
            out.println(res);
        }

    }

    private static int[][] graph(InputReader inp, int n, int m, boolean undirected, boolean reduce) {
        int[][] g = new int[n][];
        int[][] edges = new int[m][2];
        int[] out_degree = new int[n];
        int[] cnt = new int[n];
        for (int i = 0; i < m; i++) {
            edges[i][0] = inp.nextInt();
            edges[i][1] = inp.nextInt();
            if (reduce) {
                edges[i][0]--;
                edges[i][1]--;
            }
            out_degree[edges[i][0]]++;
            if (undirected) out_degree[edges[i][1]]++;
        }
        for (int i = 0; i < n; i++) g[i] = new int[out_degree[i]];

        for (int[] edge: edges) {
            g[edge[0]][cnt[edge[0]]++] = edge[1];
            if (undirected) g[edge[1]][cnt[edge[1]]++] = edge[0];
        }
        return g;
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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


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

public class TheTagGame {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        int[][] g;
        int[] depths;
        int[] prev;
        boolean[] visited;
        int x, depth;

        private void dfs(int node, int depth) {
            if (visited[node]) return;
            if (node == x) this.depth = depth;
            visited[node] = true;
            depths[node] = depth;
            for (int neigh: g[node]) {
                if (!visited[neigh]) prev[neigh] = node;
                dfs(neigh, depth + 1);
            }
        }

        private int dfs2(int node, int max) {
            int temp = 0;
            for (int neigh: g[node]) {
                if (depths[neigh] > depths[node]) {
                    //System.out.println("from " + (node+1) + " to " + (neigh+1) + " depth " + max);
                    temp = Math.max(temp, dfs2(neigh, max + 1));
                }
            }
            return Math.max(max, temp);
        }

        private void solve(InputReader inp, PrintWriter out) {
            /*
            DFS until x is reached:
                - keep track of depth
                - keep track of path
                - go back (depth - 1) / 2 steps to y
            DFS from y:
                - calculate max depth path from y
                - add max depth * 2
                - if nodes between 1 and x is odd: add 4
                - if nodes between 1 and x is even: add 2
            */
            int n = inp.nextInt();
            x = inp.nextInt() - 1;
            visited = new boolean[n];
            prev = new int[n];
            g = graph(inp, n, n - 1, true,true);
            depths = new int[n];

            int res = 0;
            dfs(0, 0);
            int between = depth - 1;
            res += between / 2 * 2; //move up moves
            if ((between & 1) == 1) res += 4; //moves to reach
            else res += 2; //moves to reach
            //move up
            int i = between >> 1;
            while (i-- > 0) x = prev[x];

            //out.println("start: " + (x+1));
            int longestPath = dfs2(x, 0);
            //out.println("longest path " + longestPath);
            //out.println("depth 3 " + depths[2]);
            //out.println("depth 2 " + depths[1]);
            res += longestPath << 1;
            out.println(res);
        }

    }

    private static int[][] graph(InputReader inp, int n, int m, boolean undirected, boolean reduce) {
        int[][] g = new int[n][];
        int[][] edges = new int[m][2];
        int[] out_degree = new int[n];
        int[] cnt = new int[n];
        for (int i = 0; i < m; i++) {
            edges[i][0] = inp.nextInt();
            edges[i][1] = inp.nextInt();
            if (reduce) {
                edges[i][0]--;
                edges[i][1]--;
            }
            out_degree[edges[i][0]]++;
            if (undirected) out_degree[edges[i][1]]++;
        }
        for (int i = 0; i < n; i++) g[i] = new int[out_degree[i]];

        for (int[] edge: edges) {
            g[edge[0]][cnt[edge[0]]++] = edge[1];
            if (undirected) g[edge[1]][cnt[edge[1]]++] = edge[0];
        }
        return g;
    }

    private static void printGraph(int[][] g, boolean reduced) {
        for (int i = 0; i < g.length; i++) {
            System.out.print(reduced?(i+1)+": ":i + ": ");
            for (int j = 0; j < g[i].length; j++) {
                System.out.print(reduced?(g[i][j]+1)+" ":g[i][j]+" ");
            } System.out.print("\n");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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