#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 510;
vector<long long> adj[MAXN];
vector<long long> v1, v2;
bool mark[MAXN][MAXN][3];
long long par[MAXN][MAXN][3];
queue<pair<pair<long long, long long>, bool>> q;
long long n, m;
void bfs() {
  while (q.size()) {
    pair<pair<long long, long long>, bool> p = q.front();
    long long a = p.first.first, b = p.first.second, c = p.second;
    if (!c) {
      for (long long i = 0; i < adj[a].size(); i++) {
        long long u = adj[a][i];
        if (!mark[u][b][1]) {
          mark[u][b][1] = true;
          q.push(make_pair(make_pair(u, b), true));
          par[u][b][1] = a;
        }
      }
    }
    if (c) {
      for (long long i = 0; i < adj[b].size(); i++) {
        long long u = adj[b][i];
        if (a != u && !mark[a][u][0]) {
          mark[a][u][0] = true;
          q.push(make_pair(make_pair(a, u), false));
          par[a][u][0] = b;
        }
      }
    }
    q.pop();
  }
}
void pp(long long a, long long c, bool b) {
  if (c == n && !b && a == 1) return;
  if (!b) {
    pp(a, par[a][c][b], true);
    v2.push_back(c);
  }
  if (b) {
    pp(par[a][c][b], c, false);
    v1.push_back(a);
  }
}
int32_t main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  mark[1][n][0] = true;
  pair<pair<long long, long long>, bool> p = {{1, n}, 0};
  q.push(p);
  bfs();
  if (!mark[n][1][0]) {
    cout << -1 << endl;
    return 0;
  }
  pp(n, 1, 0);
  cout << v1.size() << endl << 1 << " ";
  for (long long i = 0; i < v1.size(); i++) cout << v1[i] << " ";
  cout << endl << n << " ";
  for (long long i = 0; i < v2.size(); i++) cout << v2[i] << " ";
  cout << endl;
  return 0;
}
