#include <bits/stdc++.h>
using namespace std;
const long long maxn = 550;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long n, m, dis[maxn][maxn][2], v, u, f, x;
pair<long long, long long> par[maxn][maxn][2];
queue<pair<pair<long long, long long>, long long> > q;
vector<long long> v1, v2;
vector<long long> g[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      dis[i][j][0] = inf;
      dis[i][j][1] = inf;
    }
  }
  dis[1][n][0] = 0;
  q.push({{1, n}, 0});
  while (!q.empty()) {
    v = q.front().first.first;
    u = q.front().first.second;
    f = q.front().second;
    q.pop();
    if (f) {
      for (long long i = 0; i < g[u].size(); i++) {
        x = g[u][i];
        if (dis[v][x][0] > dis[v][u][1] + 1) {
          dis[v][x][0] = dis[v][u][1] + 1;
          par[v][x][0] = {v, u};
          q.push({{v, x}, 0});
        }
      }
    } else {
      if (v == u) continue;
      for (long long i = 0; i < g[v].size(); i++) {
        x = g[v][i];
        if (dis[x][u][1] > dis[v][u][0] + 1) {
          dis[x][u][1] = dis[v][u][0] + 1;
          par[x][u][1] = {v, u};
          q.push({{x, u}, 1});
        }
      }
    }
  }
  if (dis[n][1][0] >= inf) {
    cout << -1;
    return 0;
  }
  cout << dis[n][1][0] / 2 << '\n';
  v = n;
  u = 1;
  f = 0;
  while (v) {
    if (f == 0) {
      v2.push_back(v);
      v1.push_back(u);
    }
    x = v;
    v = par[v][u][f].first;
    u = par[x][u][f].second;
    f = 1 - f;
  }
  for (long long i = 0; i < v1.size(); i++) {
    cout << v1[i] << " ";
  }
  cout << '\n';
  for (long long i = 0; i < v2.size(); i++) {
    cout << v2[i] << " ";
  }
  return 0;
}
