n,u,v,*L=map(int,open(0).read().split())
vis=[-1]*n
con=[[] for _ in range(n)]
for s,t in zip(*[iter(L)]*2):
	con[s-1].append(t-1)
	con[t-1].append(s-1)
vis[v-1]=0

def f(s):
	q=[s]
	vis[s]=1
	f=0
	while q:
		cur=q.pop(0)
		if cur==u-1:
			f=1
		for nxt in con[cur]:
			if vis[nxt]<0:
				vis[nxt]=vis[cur]+1
				q.append(nxt)
	if f:
		return vis[cur]
	else:
		return False

if u==v:
	print(1)
	exit()

for s in con[v-1]:
	r=f(s)
	if r:
		print(r-1)
		exit()