#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ll long long
#define ull unsigned long long
#define ld long double
#define Yes cout << "YES\n"
#define No cout << "NO\n"
using namespace std;
#define IO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
const int MX = 2e5 + 5 , MOD = 1e9 + 7;
#define all(v) v.begin() , v.end()
#define rall(v) v.rbegin() , v.rend()
#define nl '\n'
vector<vector<int>>adj(MX);
vector<int>indeg(MX);
vector<bool>vis(MX);
vector<bool>inprogg(MX);
queue<int>q;
vector<int>ans(MX);
vector<int>parent(MX);
void solve()
{
int n , m;
cin >> n >> m;
for(int i = 0; i <m ; i++){
int u,v;
cin>> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
q.push(1);
vis[1] = true;
while(!q.empty())
{
int node = q.front(); q.pop();
for(auto& i : adj[node]){
if(!vis[i]){
ans[i] = ans[node] + 1;
vis[i] = true;
q.push(i);
parent[i] = node;
}
}
}
if(!vis[n]){
cout << "IMPOSSIBLE";
return;
}
cout << ans[n] + 1 << nl;
vector<int>res;
int x = n; res.push_back(x);
while(x > 1){
res.push_back(parent[x]);
x = parent[x];
}
reverse(all(res));
for(auto& i : res)
cout << i << ' ';
}
int main()
{
FIO
#ifndef ONLINE_JUDGE
IO
#endif
int tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRklPIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpO2Npbi50aWUobnVsbHB0cik7Y291dC50aWUobnVsbHB0cik7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZwojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgWWVzIGNvdXQgPDwgIllFU1xuIgojZGVmaW5lIE5vICBjb3V0IDw8ICJOT1xuIgp1c2luZyBuY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ldID0gbm9kZTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBpZighdmlzW25dKXsKICAgICAgICBjb3V0IDw8ICJJTVBPU1NJQkxFIjsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBjb3V0IDw8IGFuc1tuXSArIDEgPDwgbmw7CiAgICB2ZWN0b3I8aW50PnJlczsKICAgIGludCB4ID0gbjsgcmVzLnB1c2hfYmFjayh4KTsKICAgIHdoaWxlKHggPiAxKXsKICAgICAgICByZXMucHVzaF9iYWNrKHBhcmVudFt4XSk7CiAgICAgICAgeCA9IHBhcmVudFt4XTsKICAgIH0KCiAgICByZXZlcnNlKGFsbChyZXMpKTsKICAgIGZvcihhdXRvJiBpIDogcmVzKQogICAgICAgIGNvdXQgPDwgaSA8PCAnICc7Cn0KCmludCBtYWluKCkKewogICAgRklPCiNpZm5kZWYgT05MSU5FX0pVREdFCiAgICBJTwojZW5kaWYKICAgIGludCB0dCA9IDE7CiAgICAvLyBjaW4gPj4gdHQ7CiAgICB3aGlsZSAodHQtLSkgewogICAgICAgIHNvbHZlKCk7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==