#include <bits/stdc++.h>
using namespace std;
int deep[300005], x, y, Q[300005], n, m, i, j, k, fa[300005], vis[300005],
    Grate[300005];
vector<int> v[300005], ans;
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void Get(int x, int y, int z) {
  ans.push_back(n);
  ans.push_back(x);
  ans.push_back(z);
  ans.push_back(y);
  ans.push_back(x);
  ans.push_back(1);
}
int Bl(int x, int y) {
  int l = 1, L = 1;
  if (v[x][l] == y) ++l;
  if (v[y][L] == x) ++L;
  while (l < v[x].size() || L < v[y].size()) {
    if (l == v[x].size()) {
      Get(x, y, v[y][L]);
      return 1;
    } else if (L == v[y].size()) {
      Get(v[x][l], x, y);
      return 1;
    } else if (v[x][l] != v[y][L]) {
      if (v[x][l] < v[y][L])
        Get(v[x][l], x, y);
      else
        Get(x, y, v[y][L]);
      return 1;
    } else
      ++l, ++L;
    if (v[x][l] == y) ++l;
    if (v[y][L] == x) ++L;
  }
  return 0;
}
void bfs(int x) {
  int i, p;
  Q[Q[0] = 1] = x;
  memset(deep, -1, sizeof(deep));
  deep[x] = 0;
  for (int l = 1; l <= Q[0]; ++l) {
    int p = Q[l];
    for (i = 0; i < (int)v[p].size(); ++i) {
      int k = v[p][i];
      if (deep[k] != -1) continue;
      deep[k] = deep[p] + 1;
      fa[k] = p;
      Q[++Q[0]] = k;
    }
  }
  if (deep[n] != -1 && deep[n] <= 3) {
    for (i = n; i; i = fa[i]) ans.push_back(i);
    return;
  }
  for (i = 1; i <= Q[0]; ++i)
    if (deep[Q[i]] == 2) {
      ans.push_back(n);
      ans.push_back(1);
      ans.push_back(Q[i]);
      ans.push_back(fa[Q[i]]);
      ans.push_back(1);
      return;
    }
  for (i = 1; i <= n; ++i) fa[i] = i;
  for (i = 1; i <= n; ++i) sort(v[i].begin(), v[i].end());
  for (int l = 2; l <= Q[0]; ++l) {
    int p = Q[l];
    for (j = 0; j < (int)v[p].size(); ++j)
      if (v[p][j] != 1) {
        int k = v[p][j];
        if (get(p) == get(k)) continue;
        if (Bl(p, k)) return;
        fa[p] = k;
      }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfs(1);
  printf("%d\n", ans.size() - 1);
  for (i = ans.size() - 1; i >= 0; --i) printf("%d ", ans[i]);
}
