#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxN = 1e3 + 13;
vector<int> adj[maxN];
int sp[maxN][maxN];
pair<int, int> par[maxN][maxN];
queue<pair<int, int>> qu;
vector<int> vec1, vec2;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  sp[1][n] = 1;
  qu.push({1, n});
  par[1][n] = {0, 0};
  while (qu.size()) {
    int u = qu.front().first, v = qu.front().second;
    qu.pop();
    if (u != v) {
      for (auto a : adj[u])
        for (auto b : adj[v]) {
          if (!sp[a][b]) {
            sp[a][b] = sp[u][v] + 1;
            qu.push({a, b});
            par[a][b] = {u, v};
          }
        }
    }
  }
  int x = n, y = 1;
  if (!sp[x][y]) return cout << -1 << endl, 0;
  while (x + y > 0) {
    vec1.push_back(x);
    vec2.push_back(y);
    int tmp = par[x][y].first;
    y = par[x][y].second;
    x = tmp;
  }
  cout << vec1.size() - 1 << endl;
  for (int i = 0; i < vec2.size(); i++) cout << vec2[i] << " ";
  cout << endl;
  for (int i = 0; i < vec1.size(); i++) cout << vec1[i] << " ";
}
