#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7, maxn = 5e2 + 500;
bool visited[maxn][maxn][2];
int dp[maxn][maxn][2], n;
pair<pair<int, int>, bool> par[maxn][maxn][2];
vector<int> v[maxn];
queue<pair<pair<int, int>, bool> > qu;
void bfs(int a, int b) {
  visited[a][b][0] = 1;
  qu.push(make_pair(make_pair(a, b), 0));
  par[a][b][0] = make_pair(make_pair(-1, -1), 1);
  dp[a][b][0] = 0;
  while (!qu.empty()) {
    int a = qu.front().first.first;
    int b = qu.front().first.second;
    int c = qu.front().second;
    if (c == 0) {
      for (auto w : v[a]) {
        if (!visited[w][b][1]) {
          dp[w][b][1] = dp[a][b][0];
          qu.push(make_pair(make_pair(w, b), 1));
          visited[w][b][1] = 1;
          par[w][b][1] = make_pair(make_pair(a, b), 0);
        }
      }
    } else {
      for (auto w : v[b]) {
        if (w == a) continue;
        if (!visited[a][w][0]) {
          dp[a][w][0] = dp[a][b][1] + 1;
          qu.push(make_pair(make_pair(a, w), 0));
          visited[a][w][0] = 1;
          par[a][w][0] = make_pair(make_pair(a, b), 1);
        }
      }
    }
    qu.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, w;
    cin >> u >> w;
    v[u].push_back(w);
    v[w].push_back(u);
  }
  memset(dp, -1, sizeof dp);
  bfs(1, n);
  if (dp[n][1][0] != -1) {
    cout << dp[n][1][0] << endl;
    vector<int> ans1, ans2;
    ans2.push_back(1);
    int a = n, b = 1, c = 0;
    while (a != -1 and b != -1) {
      if (c == 0)
        ans1.push_back(a);
      else
        ans2.push_back(b);
      int tmp = par[a][b][c].first.first;
      int tm = par[a][b][c].first.second;
      a = tmp;
      b = tm;
      c ^= 1;
    }
    for (int i = ans1.size() - 1; i >= 0; i--) cout << ans1[i] << " ";
    cout << endl;
    for (int i = ans2.size() - 1; i >= 0; i--) cout << ans2[i] << " ";
    cout << endl;
  } else
    cout << -1 << endl;
}
