#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
// GCD function using long double. Recommend switching to integer types for precision.
ll Gcd(ll a, ll b) {
if (b == 0) return a;
return Gcd(b, a % b);
}
// Modular exponentiation
ll fpower(ll n, ll e, ll m) {
if (e == 0) return 1;
if (e == 1) return n % m;
ll ret = 1;
if (e & 1) ret = n % m;
ll x = fpower(n, e / 2, m);
ret = ret * x % m * x % m;
return ret % m;
}
// Sieve of Eratosthenes for smallest prime divisors
vector<int> sel2(int n) {
vector<int> d(n + 1, -1);
for (int i = 2; i <= n; ++i) {
for (int j = i; j <= n; j += i) {
if (d[j] == -1) {
d[j] = i;
}
}
}
return d;
}
vector<int> prime_factors(int n) {
vector<int> factors;
for (int i = 2; i * i <= n; i++) {
int count = 0;
while (n % i == 0) {
n /= i;
count++;
}
if (count > 0) {
factors.push_back(i);
}
}
if (n > 1)
factors.push_back(n);
return factors;
}
// Standard sieve of Eratosthenes for primes
vector<bool> sel(ll n) {
vector<bool> d(n + 1, true);
d[0] = false;
d[1] = false;
for (ll i = 2; i * i <= n; ++i) {
if (d[i]) {
for (ll j = i * i; j <= n; j += i) {
d[j] = false;
}
}
}
return d;
}
// Bit manipulation functions
ll setbit(ll n, ll idx) {
return (n >> idx) & 1LL;
}
ll flip(ll n, ll idx) {
return (1LL << idx) ^ n;
}
ll set1(ll n, ll idx) {
return (1 << idx) | n;
}
const int N = 2e5 + 6;
ll n, m;
int d=0;
vector<int> h[N];
vector<int> r2(N);
vector<bool> vis(N);
vector<int> par(N);
int dfs(int node, int parent) {
int sum = 0;
for (int neighbor : h[node]) {
if (neighbor != parent) {
int subtree_size = dfs(neighbor, node);
sum += subtree_size;
}
}
r2[node] = sum + 1;
return r2[node];
}
void bfs(int start , int end){
queue<int>q;
q.emplace(start);
while (!q.empty()){
int node=q.front();
q.pop();
vis[node]= true;
for (int neighbor : h[node]) {
if (!vis[neighbor]) {
par[neighbor]=node;
q.emplace(neighbor);
}
}
}
}
int ask(int s){
cout<<s<<"\n";
cout.flush();
string c;
cin>>c;
if(c=="yes"){
return 1;
}else{
return 0;
}
}
void solve(){
cin>>n>>m;
for (int i = 0; i < m; ++i) {
int a,b;
cin>>a>>b;
h[a].push_back(b);
h[b].push_back(a);
}
bfs(1,n);
if(!vis[n]){
cout<<"IMPOSSIBLE";
return;
}
int x=par[n];
vector<ll>tr;
tr.push_back(n);
while (x>1){
tr.push_back(x);
x=par[x];
}
cout<<tr.size()+1<<"\n";
cout<<1<<" ";
for (int i = tr.size()-1; i>=0; --i) {
cout<<tr[i]<<" ";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
while (t--) {
solve();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGxkIGxvbmcgZG91YmxlCiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZwoKLy8gR0NEIGZ1bmN0aW9uIHVzaW5nIGxvbmcgZG91YmxlLiBSZWNvbW1lbmQgc3dpdGNoaW5nIHRvIGludGVnZXIgdHlwZXMgZm9yIHByZWNpc2lvbi4KbGwgR2NkKGxsIGEsIGxsIGIpIHsKICAgIGlmIChiID09IDApIHJldHVybiBhOwogICAgcmV0dXJuIEdjZChiLCBhICUgYik7Cn0KCi8vIE1vZHVsYXIgZXhwb25lbnRpYXRpb24KbGwgZnBvd2VyKGxsIG4sIGxsIGUsIGxsIG0pIHsKICAgIGlmIChlID09IDApIHJldHVybiAxOwogICAgaWYgKGUgPT0gMSkgcmV0dXJuIG4gJSBtOwogICAgbGwgcmV0ID0gMTsKICAgIGlmIChlICYgMSkgcmV0ID0gbiAlIG07CiAgICBsbCB4ID0gZnBvd2VyKG4sIGUgLyAyLCBtKTsKICAgIHJldCA9IHJldCAqIHggJSBtICogeCAlIG07CiAgICByZXR1cm4gcmV0ICUgbTsKfQoKLy8gU2lldmUgb2YgRXJhdG9zdGhlbmVzIGZvciBzbWFsbGVzdCBwcmltZSBkaXZpc29ycwp2ZWN0b3I8aW50PiBzZWwyKGludCBuKSB7CiAgICB2ZWN0b3I8aW50PiBkKG4gKyAxLCAtMSk7CiAgICBmb3IgKGludCBpID0gMjsgaSA8PSBuOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gaTsgaiA8PSBuOyBqICs9IGkpIHsKICAgICAgICAgICAgaWYgKGRbal0gPT0gLTEpIHsKICAgICAgICAgICAgICAgIGRbal0gPSBpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGQ7Cn0KCnZlY3RvcjxpbnQ+IHByaW1lX2ZhY3RvcnMoaW50IG4pIHsKICAgIHZlY3RvcjxpbnQ+IGZhY3RvcnM7CiAgICBmb3IgKGludCBpID0gMjsgaSAqIGkgPD0gbjsgaSsrKSB7CiAgICAgICAgaW50IGNvdW50ID0gMDsKICAgICAgICB3aGlsZSAobiAlIGkgPT0gMCkgewogICAgICAgICAgICBuIC89IGk7CiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgfQogICAgICAgIGlmIChjb3VudCA+IDApIHsKICAgICAgICAgICAgZmFjdG9ycy5wdXNoX2JhY2soaSk7CiAgICAgICAgfQogICAgfQogICAgaWYgKG4gPiAxKQogICAgICAgIGZhY3RvcnMucHVzaF9iYWNrKG4pOwoKICAgIHJldHVybiBmYWN0b3JzOwp9CgovLyBTdGFuZGFyZCBzaWV2ZSBvZiBFcmF0b3N0aGVuZXMgZm9yIHByaW1lcwp2ZWN0b3I8Ym9vbD4gc2VsKGxsIG4pIHsKICAgIHZlY3Rvcjxib29sPiBkKG4gKyAxLCB0cnVlKTsKICAgIGRbMF0gPSBmYWxzZTsKICAgIGRbMV0gPSBmYWxzZTsKICAgIGZvciAobGwgaSA9IDI7IGkgKiBpIDw9IG47ICsraSkgewogICAgICAgIGlmIChkW2ldKSB7CiAgICAgICAgIC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iAgICAgICAgdmlzW25vZGVdPSB0cnVlOwogICAgICAgIGZvciAoaW50IG5laWdoYm9yIDogaFtub2RlXSkgewogICAgICAgICAgICBpZiAoIXZpc1tuZWlnaGJvcl0pIHsKICAgICAgICAgICAgICAgIHBhcltuZWlnaGJvcl09bm9kZTsKICAgICAgICAgICAgICAgIHEuZW1wbGFjZShuZWlnaGJvcik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KaW50IGFzayhpbnQgcyl7CiAgICBjb3V0PDxzPDwiXG4iOwogICAgY291dC5mbHVzaCgpOwogICAgc3RyaW5nIGM7CiAgICBjaW4+PmM7CiAgICBpZihjPT0ieWVzIil7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9ZWxzZXsKICAgICAgICByZXR1cm4gMDsKICAgIH0KfQp2b2lkIHNvbHZlKCl7CiAgICBjaW4+Pm4+Pm07CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIGludCBhLGI7CiAgICAgICAgY2luPj5hPj5iOwogICAgICAgIGhbYV0ucHVzaF9iYWNrKGIpOwogICAgICAgIGhbYl0ucHVzaF9iYWNrKGEpOwogICAgfQogICAgYmZzKDEsbik7CgogICAgaWYoIXZpc1tuXSl7CiAgICAgICAgY291dDw8IklNUE9TU0lCTEUiOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIGludCB4PXBhcltuXTsKICAgIHZlY3RvcjxsbD50cjsKICAgIHRyLnB1c2hfYmFjayhuKTsKICAgIHdoaWxlICh4PjEpewogICAgICAgIHRyLnB1c2hfYmFjayh4KTsKICAgICAgICB4PXBhclt4XTsKICAgIH0KICAgIGNvdXQ8PHRyLnNpemUoKSsxPDwiXG4iOwogICAgY291dDw8MTw8IiAiOwogICAgZm9yIChpbnQgaSA9IHRyLnNpemUoKS0xOyBpPj0wOyAtLWkpIHsKICAgICAgICBjb3V0PDx0cltpXTw8IiAiOwogICAgfQp9CmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgY291dC50aWUobnVsbHB0cik7CiAgICBpbnQgdD0xOwogICAgd2hpbGUgKHQtLSkgewogICAgICAgIHNvbHZlKCk7CiAgIH0KfQ==