#include <bits/stdc++.h>
 
 
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx2,fma")
using namespace std;
#define ll long long
#define int ll
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define pb push_back
#define yes cout<<"YES"
#define no cout<<"NO"
#define endl '\n'
#define endll cout<<endl
#define Fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define F first
#define S second
#define im cout<<"IMPOSSIBLE"
const int N = 5e5 + 11;
const int NN = 106;
const int mo = 1e9 + 123;
const int mod = 1e9 + 7;
const int m = 1e9 + 123;
const int Mod = 998244353;
const ll inf = 1e18;
const int LOG = 19;
#define PI 3.14159265
 
 
int Lcm(int x, int y) {
    return x / __gcd(x, y) * y;
}
 
vector<int> v[N];
int vis[N];
int dist[N], par[N];
 
void bfs(int node) {
    queue<int> q;
    q.push(node);
    vis[node] = 1;
    while (q.size()) {
        int x = q.front();
        q.pop();
        for (auto i: v[x]) {
            if (vis[i])continue;
            q.push(i);
            vis[i] = 1;
            dist[i] = dist[x] + 1;
            par[i] = x;
        }
    }
}
 
void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    if (vis[n]) {
        vector<int> ans;
        int node = n;
        while (node != 1) {
            ans.pb(node);
            node = par[node];
        }
        ans.pb(1);
        cout << dist[n] + 1 << endl;
        reverse(all(ans));
        for (auto i: ans)
            cout << i << " ";
        endll;
    } else cout << "IMPOSSIBLE";
}
 
 
int32_t main() {
    Fast;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    for (int i = 1; i < t + 1; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}