#include <bits/stdc++.h>
using namespace std;
const int MAX = 505;
const long long MOD = 1e9 + 7;
vector<int> g[MAX];
queue<pair<pair<int, int>, int>> q;
int dis[MAX][MAX][2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  memset(dis, -1, sizeof(dis));
  dis[0][n - 1][0] = MAX;
  q.push({{0, n - 1}, 0});
  while (q.size()) {
    int v = q.front().first.first;
    int u = q.front().first.second;
    int t = q.front().second;
    q.pop();
    if (v == u && t == 0) continue;
    if (t == 0) {
      for (auto x : g[v])
        if (dis[x][u][1] == -1) {
          dis[x][u][1] = v;
          q.push({{x, u}, 1});
        }
    } else
      for (auto x : g[u])
        if (dis[v][x][0] == -1) {
          dis[v][x][0] = u;
          q.push({{v, x}, 0});
        }
  }
  if (dis[n - 1][0][0] == -1) return cout << "-1\n", 0;
  vector<int> res[2];
  if (dis[n - 1][0][0] != -1) {
    int a, b, t;
    a = n - 1;
    b = 0;
    t = 0;
    while (dis[a][b][t] != MAX) {
      if (t == 0)
        res[1].push_back(b);
      else
        res[0].push_back(a);
      if (t == 0)
        b = dis[a][b][t];
      else
        a = dis[a][b][t];
      t = 1 - t;
    }
  }
  res[0].push_back(0);
  res[1].push_back(n - 1);
  reverse(res[0].begin(), res[0].end());
  reverse(res[1].begin(), res[1].end());
  cout << res[0].size() - 1 << "\n";
  for (auto x : res[0]) cout << x + 1 << " ";
  cout << "\n";
  for (auto x : res[1]) cout << x + 1 << " ";
  cout << "\n";
}
