#include <bits/stdc++.h>
using namespace std;
const long long int N = 500 + 10, N2 = 4e6, delta = 46639, mod = 998244353,
                    oo = 1e18, LOG = 20;
const long double PI = 3.141592653589793;
bool mark[N][N];
vector<long long int> v[N], path1, path2;
pair<long long int, long long int> par[N][N];
void p(long long int x, long long int y) {
  if (x == -1 || y == -1) return;
  path1.push_back(x);
  path2.push_back(y);
  p(par[x][y].first, par[x][y].second);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    x--, y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<pair<long long int, long long int> > q;
  q.push({0, n - 1});
  mark[0][n - 1] = true;
  par[0][n - 1] = {-1, -1};
  while (q.size()) {
    pair<long long int, long long int> p = q.front();
    if (p.first != p.second)
      for (auto u : v[p.first])
        for (auto x : v[p.second]) {
          if (!mark[u][x]) {
            q.push({u, x});
            mark[u][x] = true;
            par[u][x] = {p.first, p.second};
          }
        }
    q.pop();
  }
  if (!mark[n - 1][0]) return cout << -1, 0;
  p(n - 1, 0);
  cout << path1.size() - 1 << '\n';
  for (auto u : path2) cout << ++u << ' ';
  cout << '\n';
  for (auto u : path1) cout << ++u << ' ';
  cout << '\n';
  return 0;
}
