#include <bits/stdc++.h>
using namespace std;
int n, m, d[600][600];
vector<int> g[600];
pair<int, int> p[600][600];
vector<pair<int, int> > ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  queue<pair<int, int> > q;
  q.push({1, n});
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) d[i][j] = 0;
  d[1][n] = 1;
  p[1][n] = {-1, -1};
  while (!q.empty() && !d[n][1]) {
    int u = q.front().first;
    int v = q.front().second;
    q.pop();
    for (auto i : g[u])
      for (auto j : g[v])
        if (!d[i][j] && i != j) {
          p[i][j] = {u, v};
          d[i][j] = d[u][v] + 1;
          q.push({i, j});
        }
  }
  if (d[n][1] == 0)
    cout << -1;
  else {
    int u = n, v = 1;
    while (u != -1) {
      ans.push_back({u, v});
      auto x = p[u][v];
      u = x.first;
      v = x.second;
    }
    reverse(ans.begin(), ans.end());
    cout << ans.size() - 1 << endl;
    for (auto i : ans) cout << i.first << " ";
    cout << endl;
    for (auto i : ans) cout << i.second << " ";
  }
}
