#include <bits/stdc++.h>
using namespace std;
const int N = 505;
vector<int> adj[N];
int n, m, dist[N][N][2], p, ans;
queue<pair<pair<int, int>, bool> > Q;
pair<pair<int, int>, bool> par[N][N][2];
int main() {
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  memset(dist, -1, sizeof(dist));
  dist[1][n][0] = 0;
  Q.push(make_pair(make_pair(1, n), false));
  while (!Q.empty()) {
    pair<pair<int, int>, bool> fr = Q.front();
    Q.pop();
    int a = fr.first.first, b = fr.first.second;
    bool t = fr.second;
    if (!t) {
      for (int u : adj[a])
        if (dist[u][b][1] == -1) {
          dist[u][b][1] = dist[a][b][t];
          par[u][b][1] = fr;
          Q.push(make_pair(make_pair(u, b), true));
        }
    } else {
      for (int u : adj[b]) {
        if (u == a || dist[a][u][0] != -1) continue;
        dist[a][u][0] = dist[a][b][t] + 1;
        par[a][u][0] = fr;
        Q.push(make_pair(make_pair(a, u), false));
      }
    }
  }
  ans = dist[n][1][0];
  cout << ans << endl;
  if (ans != -1) {
    vector<int> v1, v2;
    int a = n, b = 1;
    do {
      v1.push_back(a);
      v2.push_back(b);
      for (int i = 0; i < 2; i++) {
        pair<pair<int, int>, bool> tmp;
        tmp = par[a][b][i];
        a = tmp.first.first;
        b = tmp.first.second;
      }
    } while (ans--);
    for (int x : v2) cout << x << " ";
    cout << "\n";
    for (int x : v1) cout << x << " ";
    cout << endl;
  }
}
