#include <bits/stdc++.h>
using namespace std;
const long long N = 600;
long long n, m;
pair<long long, long long> par[N][N];
long long d[N][N];
vector<long long> G[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 0, v, u; i < m; i++) {
    cin >> v >> u;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  memset(d, 63, sizeof d);
  d[1][n] = 0;
  queue<pair<long long, long long> > q;
  q.push({1, n});
  while (q.size()) {
    auto X = q.front();
    q.pop();
    long long x = X.first, y = X.second;
    for (auto xx : G[x]) {
      for (auto yy : G[y]) {
        if (xx ^ yy && d[xx][yy] > d[x][y] + 1) {
          d[xx][yy] = d[x][y] + 1;
          q.push({xx, yy});
          par[xx][yy] = {x, y};
        }
      }
    }
  }
  if (d[n][1] > 1e10) return cout << -1, 0;
  cout << d[n][1] << '\n';
  vector<long long> A, B;
  long long X = n, Y = 1;
  long long cnt = 0;
  while (!(X == 1 && Y == n)) {
    A.push_back(X);
    B.push_back(Y);
    auto P = par[X][Y];
    X = P.first;
    Y = P.second;
  }
  A.push_back(1);
  B.push_back(n);
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  for (auto u : A) cout << u << ' ';
  cout << '\n';
  for (auto u : B) cout << u << ' ';
  return (0);
}
