program main
  implicit none
  integer :: n, i, res, u, v, ios, num
  integer, allocatable :: kyoriu(:), kyoriv(:)
  integer :: a(200000), b(200000)
  read(*,*) n, u, v
  i = 0
  ios = 0
  do while(ios==0)
    i = i + 1
    read(*,*, iostat=ios) a(i), b(i)
  end do
  num = i
  allocate(kyoriu(n))
  allocate(kyoriv(n))

  kyoriu(:) = -1
  kyoriv(:) = -1

  kyoriu(u) = 0
  call search_kyori(u, 0, kyoriu)
  kyoriv(v) = 0
  call search_kyori(v, 0, kyoriv)

  write(6,*) maxval(kyoriv, mask=kyoriv>kyoriu) -1
contains
  recursive subroutine search_kyori(id, kyori, kyoris)
    implicit none
    integer :: id, kyori, kyoris(:)
    integer :: i
    do i = 1, num
      if(a(i) == id .and. kyoris(b(i)) ==-1) then
        kyoris(b(i)) = kyori + 1
        call search_kyori(b(i), kyori+1, kyoris)
      end if
    end do
    do i = 1, num
      if (b(i) == id .and. kyoris(a(i)) ==-1) then
        kyoris(a(i)) = kyori + 1
        call search_kyori(a(i), kyori+1, kyoris)
      end if
    end do
  end subroutine search_kyori
end program main