#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 10;
const int maxn5 = 5 * 1000 * 100 + 10;
const int maxnJ = 1000 + 10;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;
int h[600][600];
queue<pair<int, int>> q;
vector<int> adj[maxn5], ans1, ans2;
pair<int, int> par[600][600];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i < 600; i++)
    for (int j = 0; j < 600; j++) h[i][j] = -1;
  q.push({1, n});
  h[1][n] = 0;
  while (!q.empty()) {
    int a = q.front().first, b = q.front().second;
    q.pop();
    for (auto u : adj[a])
      for (auto v : adj[b])
        if (u != v and h[u][v] == -1) {
          h[u][v] = h[a][b] + 1;
          q.push({u, v});
          par[u][v] = {a, b};
        }
  }
  if (h[n][1] == -1) return cout << -1 << endl, 0;
  if (true) {
    if (true) {
      int a = n, b = 1;
      cout << h[a][b] << endl;
      int hv = h[a][b];
      ans1.push_back(a);
      ans2.push_back(b);
      while (hv--) {
        int x = par[a][b].first, y = par[a][b].second;
        a = x;
        b = y;
        ans1.push_back(a);
        ans2.push_back(b);
      }
      reverse(ans1.begin(), ans1.end());
      reverse(ans2.begin(), ans2.end());
      for (auto u : ans1) cout << u << ' ';
      cout << endl;
      for (auto u : ans2) cout << u << ' ';
      return cout << endl, 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
