#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1), GR(N + 1);
    Edges<int> edges;
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        G[A].push_back(B);
        GR[B].push_back(A);
        edges.emplace_back(A, B, -1);
    }
    if (M == 0) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> dist1(N + 1, INF);
    dist1[edges.begin()->src] = 0;
    dist1[edges.rbegin()->src] = 0;
    for(int i = 1; i <= N * 2; i++) {
        for(auto &e : edges) {
            if(dist1[e.src] == INF) continue;
            dist1[e.to] = min(dist1[e.to], dist1[e.src] + e.cost);
        }
    }
    vector<int> dist2(N + 1); copy(dist1.begin(), dist1.end(), dist2.begin());
    for(int i = 1; i <= N * 2; i++) {
        for(auto &e : edges) {
            if(dist2[e.src] == INF) continue;
            dist2[e.to] = min(dist2[e.to], dist2[e.src] + e.cost);
        }
    }
    if (dist1 == dist2) {
        cout << -1 << endl;
        return 0;
    }
    int s = 0, count = INF;
    vector<map<int, int>> res(N + 1);
    for (int i = 1; i <= N; i++) {
        vector<bool> check(N + 1, false);
        queue<int> explore;
        vector<int> dist(N + 1, INF);
        explore.push(i);
        dist[i] = 0;
        check[i] = true;
        while (!explore.empty()) {
            int now = explore.front();
            explore.pop();
            for (auto next : G[now]) {
                if (dist[next] > dist[now] + 1) {
                    dist[next] = dist[now] + 1;
                    res[i][next] = now;
                }
                if (check[next]) continue;
                check[next] = true;
                explore.push(next);
            }
            if (now == i) dist[i] = INF;
        }
        if (dist[i] < count) {
            s = i;
            count = dist[i];
        }
    }
    vector<int> ans = {s};
    int next = res[s][s];
    while (next != s) {
        ans.push_back(next);
        next = res[s][next];
    }
    cout << ans.size() << endl;
    for (auto temp : ans) cout << temp << endl;
}
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

vector<int> G[200005];
int aoki_d[200005], takahashi_d[200005];
bool is_end[200005];

void dfs(int u, bool is_aoki, int p=-1) {
  for (int v : G[u]) {
    if (v == p) continue;
    if (is_aoki) aoki_d[v] = aoki_d[u] + 1;
    else takahashi_d[v] = takahashi_d[u] + 1;
    dfs(v, is_aoki, u);
  }
  is_end[u] = G[u].size() == 1;
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u; --v;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(u, false);
  dfs(v, true);
  int ans = 0;
  rep(i, n) {
    if (takahashi_d[i] <= aoki_d[i] && !is_end[i]) {
      ans = max(ans, aoki_d[i]);
    }
  }
  cout << ans << endl;
  return 0;
}