#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500 + 3;
int n, m;
int dis[MAXN][MAXN][2];
vector<int> adj[MAXN];
int par[MAXN][MAXN][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dis[i][j][0] = 1e9;
      dis[i][j][1] = 1e9;
      par[i][j][0] = -1;
      par[i][j][1] = -1;
    }
  }
  dis[0][n - 1][0] = 0;
  queue<pair<pair<int, int>, int> > s;
  s.push({{0, n - 1}, 0});
  while (s.size()) {
    int v = s.front().first.first;
    int u = s.front().first.second;
    int bl = s.front().second;
    s.pop();
    if (v != u || bl) {
      if (!bl) {
        for (int i = 0; i < adj[v].size(); i++) {
          int p = adj[v][i];
          if (dis[v][u][bl] + 1 < dis[p][u][!bl]) {
            dis[p][u][!bl] = dis[v][u][bl] + 1;
            par[p][u][!bl] = v;
            s.push({{p, u}, !bl});
          }
        }
      } else {
        for (int i = 0; i < adj[u].size(); i++) {
          int p = adj[u][i];
          if (dis[v][u][bl] + 1 < dis[v][p][!bl]) {
            dis[v][p][!bl] = dis[v][u][bl] + 1;
            par[v][p][!bl] = u;
            s.push({{v, p}, !bl});
          }
        }
      }
    }
  }
  if (dis[n - 1][0][0] >= 1e9) {
    cout << -1 << endl;
    return 0;
  } else {
    vector<int> vec1, vec2;
    vec1.push_back(n - 1);
    vec2.push_back(0);
    int a = n - 1;
    int b = 0;
    while (par[a][b][0] != -1) {
      int aa = par[a][b][0];
      b = aa;
      int bb = par[a][b][1];
      a = bb;
      vec1.push_back(a), vec2.push_back(b);
    }
    cout << dis[n - 1][0][0] / 2 << endl;
    while (vec1.size()) {
      cout << vec1.back() + 1 << " ";
      vec1.pop_back();
    }
    cout << endl;
    while (vec2.size()) {
      cout << vec2.back() + 1 << " ";
      vec2.pop_back();
    }
  }
  return 0;
}
