#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, l, r, tot, ans[2][1000005], hed[510];
struct node {
  int a, b, dis, pre, flag;
  node(int aa = 0, int bb = 0, int dd = 0, int pp = 0, int ff = 0) {
    a = aa;
    b = bb;
    dis = dd;
    pre = pp;
    flag = ff;
  }
};
node q[1000005];
bool visa[520][520], visb[520][520];
struct edg {
  int to, nxt;
} e[1000005];
void add(int x, int y) {
  e[++tot] = (edg){y, hed[x]};
  hed[x] = tot;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  l = r = 1;
  q[r++] = node(1, n, 0, 0, 1);
  tot = 0;
  while (l < r) {
    node p = q[l];
    if (p.a == n && p.b == 1 && p.flag == 1) {
      printf("%d\n", p.dis / 2);
      for (int i = l; i; i = q[i].pre) {
        if (q[i].flag == 1) {
          tot++;
          ans[0][tot] = q[i].a;
          ans[1][tot] = q[i].b;
        }
      }
      for (int i = tot; i >= 1; i--) printf("%d ", ans[0][i]);
      printf("\n");
      for (int i = tot; i >= 1; i--) printf("%d ", ans[1][i]);
      printf("\n");
      return 0;
    }
    if (p.flag == 1) {
      for (int i = hed[p.a]; i; i = e[i].nxt) {
        if (!visa[e[i].to][p.b]) {
          visa[e[i].to][p.b] = 1;
          q[r++] = node(e[i].to, p.b, p.dis + 1, l, 0);
        }
      }
    } else {
      for (int i = hed[p.b]; i; i = e[i].nxt) {
        if (!visb[p.a][e[i].to] && p.a != e[i].to) {
          visb[p.a][e[i].to] = 1;
          q[r++] = node(p.a, e[i].to, p.dis + 1, l, 1);
        }
      }
    }
    l++;
  }
  printf("-1");
  return 0;
}
