#include <bits/stdc++.h>
using namespace std;
const int N = 503;
vector<int> adj[N];
int d[N][N][2];
int p[N][N][2];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(d, -1, sizeof d);
  d[1][n][0] = 0;
  queue<pair<int, int> > Q[2];
  Q[0].push(pair<int, int>(1, n));
  while (!Q[0].empty()) {
    while (!Q[0].empty()) {
      int u = Q[0].front().first;
      int v = Q[0].front().second;
      Q[0].pop();
      for (vector<int>::iterator it = adj[u].begin(); it != adj[u].end(); ++it)
        if (d[*it][v][1] == -1) {
          d[*it][v][1] = d[u][v][0] + 1;
          p[*it][v][1] = u;
          Q[1].push(pair<int, int>(*it, v));
        }
    }
    while (!Q[1].empty()) {
      int u = Q[1].front().first;
      int v = Q[1].front().second;
      Q[1].pop();
      for (vector<int>::iterator it = adj[v].begin(); it != adj[v].end(); ++it)
        if (d[u][*it][0] == -1 && u != *it) {
          d[u][*it][0] = d[u][v][1];
          p[u][*it][0] = v;
          Q[0].push(pair<int, int>(u, *it));
        }
    }
  }
  if (d[n][1][0] == -1) {
    puts("-1");
    return 0;
  }
  vector<int> res[2];
  res[0].push_back(n);
  res[1].push_back(1);
  int u = n, v = 1;
  while (p[u][v][0]) {
    v = p[u][v][0];
    res[1].push_back(v);
    u = p[u][v][1];
    res[0].push_back(u);
  }
  reverse(res[0].begin(), res[0].end());
  reverse(res[1].begin(), res[1].end());
  printf("%d\n", d[n][1][0]);
  for (int i = 0; i < (int)res[0].size(); ++i) {
    if (i) printf(" ");
    printf("%d", res[0][i]);
  }
  printf("\n");
  for (int i = 0; i < (int)res[1].size(); ++i) {
    if (i) printf(" ");
    printf("%d", res[1][i]);
  }
  printf("\n");
  return 0;
}
