#include <bits/stdc++.h>
using namespace std;
const int N = 505, INF = 1e9 + 7;
int dis[N][N];
int prvx[N][N], prvy[N][N];
vector<int> adj[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dis[i][j] = INF;
  dis[1][n] = 0;
  queue<int> q;
  q.push(1);
  q.push(n);
  while (q.size()) {
    int u = q.front();
    q.pop();
    int v = q.front();
    q.pop();
    for (int x : adj[u])
      for (int y : adj[v])
        if (dis[x][y] == INF && x != y) {
          dis[x][y] = 1 + dis[u][v];
          q.push(x);
          q.push(y);
          prvx[x][y] = u;
          prvy[x][y] = v;
        }
    if (dis[n][1] < INF) break;
  }
  if (dis[n][1] == INF)
    cout << -1 << endl;
  else {
    cout << dis[n][1] << endl;
    int ca = n, cb = 1;
    vector<int> ra, rb;
    while (ca != 1 || cb != n) {
      ra.push_back(ca);
      rb.push_back(cb);
      int na = prvx[ca][cb];
      int nb = prvy[ca][cb];
      ca = na;
      cb = nb;
      assert(ca && cb);
    }
    ra.push_back(1);
    rb.push_back(n);
    reverse(ra.begin(), ra.end());
    reverse(rb.begin(), rb.end());
    for (int x : ra) cout << x << " ";
    cout << endl;
    for (int x : rb) cout << x << " ";
    cout << endl;
  }
}
