CSES - Shared codeLink to this code: https://cses.fi/paste/790257604173567924c0d4/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define back(i,a,b) for(ll i =a;i>=b;i--)
ll pw(ll a, ll b) { ll g = 1; rep(i, 1, b) g *= a; return g;}
#define all(x) x.begin(),x.end()
bool comp(ll a, ll b) {
    //for condition that has to true we have to return 1 and for condition that has to followed
    //false we have to   return 0;
    if (a > b)
        return 1;
    return 0;
}
void print(vi v) {
    for (auto f : v)
        cout << f << " ";
}
vi adj[100001];
ll dist[100001];
vi vis(100001, 0);// use endl in interactive problems
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fill(dist, dist + 100001, 1e10);
    ll n  , m;
    cin >> n >> m;
    map<ll, ll> m1;
    while (m--) {
        ll a, b;
        cin >> a >> b;
        adj[a].PB(b);
    }
    priority_queue<pi, vector<pi>  , greater<pi > > pq;
    pq.push({0, 1});
    while (pq.size() > 0) {
        pi g = pq.top();
        pq.pop();
        if (vis[g.S] == 0)
            vis[g.S] = 1;
        else
            continue;
        for (auto u : adj[g.S]) {
            ll w = -1;
            ll b = u;
            if (dist[b] > g.F + w) {
                m1[b] = g.S;
                dist[b] = g.F + w;
                pq.push({dist[b], b});
            }
        }

    }
    if (vis[n] == 0) {
        cout << "IMPOSSIBLE\n";
    }
    else
    {
        // cout << abs(dist[n]) + 1 << "\n";
        vi ans;
        while (n != 1) {
            ans.PB(n);
            // cout << n << " ";
            n = m1[n];
        }

        ans.PB(1);
        cout << ans.size() << "\n";
        reverse(all(ans));
        print(ans);
    }



}