#include <bits/stdc++.h>
using namespace std;
int n, m, ans, prex[505][505][2], prey[505][505][2], prez[505][505][2];
bool vis[505][505][2];
vector<int> eg[505];
struct node {
  int u, v, d, st;
};
void prt(int a, int b, int c) {
  int a2 = prex[a][b][c];
  if (a2 == -1) {
    if (c == 1) printf("%d ", a);
    return;
  }
  int b2 = prey[a][b][c];
  int c2 = prez[a][b][c];
  prt(a2, b2, c2);
  if (c == 1) printf("%d ", a);
}
void prt2(int a, int b, int c) {
  int a2 = prex[a][b][c];
  if (a2 == -1) {
    if (!c) printf("%d ", b);
    return;
  }
  int b2 = prey[a][b][c];
  int c2 = prez[a][b][c];
  prt2(a2, b2, c2);
  if (!c) printf("%d ", b);
}
void bfs() {
  queue<struct node> q;
  struct node st;
  st.u = 1;
  st.v = n;
  st.d = 0;
  st.st = 0;
  vis[1][n][0] = 1;
  q.push(st);
  while (!q.empty()) {
    struct node u = q.front();
    q.pop();
    if (u.u == n && u.v == 1 && !u.st) {
      ans = u.d;
      printf("%d\n1 ", u.d);
      prt(u.u, u.v, u.st);
      printf("\n");
      prt2(u.u, u.v, u.st);
      printf("\n");
      return;
    }
    if (!u.st) {
      for (int i = 0; i < eg[u.u].size(); i++) {
        int v = eg[u.u][i];
        if (!vis[v][u.v][1]) {
          vis[v][u.v][1] = 1;
          struct node tt;
          tt.u = v;
          tt.v = u.v;
          tt.st = 1;
          tt.d = u.d;
          prex[tt.u][tt.v][tt.st] = u.u;
          prey[tt.u][tt.v][tt.st] = u.v;
          prez[tt.u][tt.v][tt.st] = u.st;
          q.push(tt);
        }
      }
    } else {
      for (int i = 0; i < eg[u.v].size(); i++) {
        int v = eg[u.v][i];
        if (!vis[u.u][v][0] && v != u.u) {
          vis[u.u][v][0] = 1;
          struct node tt;
          tt.u = u.u;
          tt.v = v;
          tt.st = 0;
          tt.d = u.d + 1;
          prex[tt.u][tt.v][tt.st] = u.u;
          prey[tt.u][tt.v][tt.st] = u.v;
          prez[tt.u][tt.v][tt.st] = u.st;
          q.push(tt);
        }
      }
    }
  }
}
int main() {
  ans = (1e9 + 7);
  memset(prex, -1, sizeof(prex));
  memset(vis, 0, sizeof(vis));
  scanf("%d%d", &n, &m);
  for (int i = 1, a, b; i <= m; i++) {
    scanf("%d%d", &a, &b);
    eg[a].push_back(b);
    eg[b].push_back(a);
  }
  bfs();
  if (ans == (1e9 + 7)) printf("-1\n");
  return 0;
}
