#include <bits/stdc++.h>
using namespace std;
const int MAX = 510, MAX2 = 1e4 + 10;
struct node {
  int x, y, c;
};
bool mark[MAX][MAX][2];
node make_node(int x, int y, int c) {
  node n;
  n.x = x, n.y = y, n.c = c;
  mark[x][y][c] = true;
  return n;
}
int n, m;
vector<int> g[MAX];
node fa[MAX][MAX][2];
bool bfs() {
  queue<node> q;
  q.push(make_node(0, n - 1, 0));
  while (q.size()) {
    node u = q.front();
    q.pop();
    if (!u.c) {
      for (int i = 0; i < g[u.x].size(); i++)
        if (!mark[g[u.x][i]][u.y][1])
          q.push(make_node(g[u.x][i], u.y, 1)),
              fa[g[u.x][i]][u.y][1] = make_node(u.x, u.y, u.c);
    } else {
      for (int i = 0; i < g[u.y].size(); i++)
        if (!mark[u.x][g[u.y][i]][0] && u.x != g[u.y][i])
          q.push(make_node(u.x, g[u.y][i], 0)),
              fa[u.x][g[u.y][i]][0] = make_node(u.x, u.y, u.c);
    }
    if (u.x == n - 1 && u.y == 0 && u.c == 0) return true;
  }
  return false;
}
vector<int> ans1, ans2;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (!bfs()) {
    cout << -1 << endl;
    return 0;
  }
  node no = make_node(n - 1, 0, 0);
  while (no.x != 0 || no.y != n - 1 || no.c != 0) {
    ans1.push_back(no.x);
    ans2.push_back(no.y);
    no = fa[no.x][no.y][no.c];
  }
  ans1.push_back(0);
  ans2.push_back(n - 1);
  reverse(ans1.begin(), ans1.end());
  reverse(ans2.begin(), ans2.end());
  cout << (int)floor(ans1.size() * 1.0 / 2) << endl;
  for (int i = 0; i < ans1.size(); i += 2) cout << ans1[i] + 1 << " ";
  cout << endl;
  for (int i = 0; i < ans2.size(); i += 2) cout << ans2[i] + 1 << " ";
  return 0;
}
