#include <bits/stdc++.h>
using namespace std;
int a[505][505], na[505];
int b[505][505];
int last[505][505][2];
int Q[500005];
int c[505][505];
int main(void) {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d", &x, &y);
    a[x][na[x]++] = y;
    a[y][na[y]++] = x;
  }
  int qb = 0, qe = 0;
  qb = qe = 0;
  Q[qe++] = 1;
  Q[qe++] = n;
  b[1][n] = 1;
  last[1][n][0] = -1;
  while (qb < qe && !b[n][1]) {
    x = Q[qb++];
    y = Q[qb++];
    int w[505] = {}, nw = 0;
    for (int j = 0; j < na[y]; j++)
      if (c[x][a[y][j]] == 0) {
        w[nw++] = a[y][j];
        c[x][a[y][j]] = 1;
      }
    for (int i = 0; i < na[x]; i++)
      for (int j = 0; j < nw; j++)
        if (a[x][i] != w[j]) {
          if (last[a[x][i]][w[j]][0] == 0) {
            b[a[x][i]][w[j]] = b[x][y] + 1;
            last[a[x][i]][w[j]][0] = x;
            last[a[x][i]][w[j]][1] = y;
            Q[qe++] = a[x][i];
            Q[qe++] = w[j];
          }
        }
  }
  if (qb == qe) {
    puts("-1");
  } else {
    x = n, y = 1;
    vector<pair<int, int> > sol;
    while (x > 0) {
      sol.push_back(make_pair(x, y));
      int tx = last[x][y][0];
      int ty = last[x][y][1];
      x = tx;
      y = ty;
    }
    printf("%d\n", sol.size() - 1);
    for (int i = 0; i < sol.size(); i++) printf("%d ", sol[i].second);
    puts("");
    for (int i = 0; i < sol.size(); i++) printf("%d ", sol[i].first);
  }
  return 0;
}
