#include <bits/stdc++.h>
using namespace std;
const int mod = 1LL * 1000 * 1000 * 1000 + 7;
const int inf = 1000 * 1000 * 1000;
const int rad = 1000;
const int maxn = 500 + 10;
int dp[maxn][maxn][3];
bool mark[maxn][maxn][3];
vector<int> adj[maxn];
struct state {
  int fi, se, mod;
};
state par[maxn][maxn][3];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int fi, se;
    cin >> fi >> se;
    adj[fi].push_back(se);
    adj[se].push_back(fi);
  }
  for (int i = 0; i < maxn; ++i)
    for (int j = 0; j < maxn; ++j)
      for (int k = 0; k < 3; ++k) dp[i][j][k] = inf;
  dp[n][1][1] = 0;
  mark[n][1][1] = 1;
  queue<state> q;
  state A;
  A.fi = n, A.se = 1, A.mod = 1;
  q.push(A);
  while (q.size()) {
    state now = q.front();
    q.pop();
    int mod = now.mod, fi = now.fi, se = now.se;
    if (mod == 1) {
      for (int i = 0; i < adj[se].size(); ++i) {
        int u = adj[se][i];
        if (fi != se && mark[fi][u][2] == 0) {
          mark[fi][u][2] = 1;
          par[fi][u][2] = now;
          dp[fi][u][2] = dp[fi][se][1] + 1;
          A.fi = fi, A.se = u, A.mod = 2;
          q.push(A);
        }
      }
    } else {
      for (int i = 0; i < adj[fi].size(); ++i) {
        int u = adj[fi][i];
        if (u != se && mark[u][se][1] == 0) {
          mark[u][se][1] = 1;
          dp[u][se][1] = dp[fi][se][2];
          par[u][se][1] = now;
          A.fi = u, A.se = se, A.mod = 1;
          q.push(A);
        }
      }
    }
  }
  if (dp[1][n][1] == inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << dp[1][n][1] << endl << 1 << ' ';
  A.fi = 1, A.se = n, A.mod = 1;
  vector<int> ans[3];
  while (true) {
    if (A.fi == n && A.se == 1 && A.mod == 1) break;
    state P = par[A.fi][A.se][A.mod];
    if (A.mod == 1)
      ans[1].push_back(P.fi);
    else
      ans[2].push_back(P.se);
    A = P;
  }
  for (int i = 0; i < ans[1].size(); ++i) cout << ans[1][i] << ' ';
  cout << endl << n << ' ';
  for (int i = 0; i < ans[2].size(); ++i) cout << ans[2][i] << ' ';
  cout << endl;
  return 0;
}
