#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> adj[500 + 1];
void link(int u, int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
int d[500 + 1][500 + 1][2];
struct state {
  int u1, u2;
  bool first;
} p[500 + 1][500 + 1][2];
void bfs(int n) {
  memset(d, -1, sizeof d);
  d[1][n][1] = 0;
  p[1][n][1] = {-1, -1};
  queue<state> q;
  q.push({1, n, 1});
  while (not q.empty()) {
    int u1 = q.front().u1;
    int u2 = q.front().u2;
    bool first = q.front().first;
    q.pop();
    for (int v : adj[first ? u1 : u2]) {
      int v1 = first ? v : u1;
      int v2 = first ? u2 : v;
      if ((first or v1 != v2) and d[v1][v2][not first] == -1) {
        d[v1][v2][not first] = d[u1][u2][first] + 1;
        p[v1][v2][not first] = {u1, u2, first};
        q.push({v1, v2, not first});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    link(u, v);
  }
  bfs(n);
  if (d[n][1][1] != -1) {
    vector<int> a, b = {1};
    state cur = {n, 1, 1};
    while (cur.u1 > 0 and cur.u2 > 0) {
      (cur.first ? a : b).push_back((cur.first ? cur.u1 : cur.u2));
      cur = p[cur.u1][cur.u2][cur.first];
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    cout << d[n][1][1] / 2 << '\n';
    for (int x : a) cout << x << " ";
    cout << '\n';
    for (int x : b) cout << x << " ";
    cout << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
