#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 11, inf = 1e9 + 10;
int n, m, v, u;
vector<int> g[N];
bool mark[N][N];
pair<int, int> dis[N][N], par[N][N];
queue<pair<int, int> > q;
vector<int> alex, bob;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> v >> u;
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dis[i][j] = {inf, inf};
  dis[0][n - 1].first = dis[0][n - 1].second = 0;
  q.push({0, n - 1});
  mark[0][n - 1] = true;
  while (!q.empty()) {
    int a = q.front().first, b = q.front().second;
    q.pop();
    for (int v : g[a])
      for (int u : g[b]) {
        if (mark[v][u]) continue;
        if (v == u) continue;
        if (max(dis[v][u].first, dis[v][u].second) >
            1 + max(dis[a][b].first, dis[a][b].second)) {
          dis[v][u].first = dis[a][b].first + 1;
          dis[v][u].second = dis[a][b].second + 1;
          par[v][u] = {a, b};
        }
        q.push({v, u});
        mark[v][u] = true;
      }
  }
  if (max(dis[n - 1][0].first, dis[n - 1][0].second) == inf)
    return cout << -1, 0;
  int ans = max(dis[n - 1][0].first, dis[n - 1][0].second);
  cout << ans << '\n';
  int a = n - 1, b = 0;
  while (alex.size() < ans) {
    alex.push_back(a);
    bob.push_back(b);
    pair<int, int> o = par[a][b];
    a = o.first, b = o.second;
  }
  alex.push_back(0);
  bob.push_back(n - 1);
  reverse(alex.begin(), alex.end());
  reverse(bob.begin(), bob.end());
  for (int i : alex) cout << i + 1 << ' ';
  cout << '\n';
  for (int i : bob) cout << i + 1 << ' ';
}
