#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
   ifstream fin("input.txt");
   ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int graph[10][10] = { 
   {0,1,0,0,0,0,0,0,0,0},
   {1,0,1,0,0,0,0,0,0,0},
   {0,1,0,1,0,0,0,0,0,0},
   {0,0,1,0,1,0,0,0,0,0},
   {0,0,0,1,0,1,0,0,0,0},
   {0,0,0,0,1,0,1,0,0,0},
   {0,0,0,0,0,0,0,1,0,0},
   {0,0,0,0,0,0,0,0,1,0},
   {0,0,0,0,0,0,0,0,0,1},
   {0,0,0,0,0,1,0,0,0,0}
};

int sol[10];

void print(int i,int e){
   if( i == -1)return;
   print( sol[i] , 0);
   if( e ){
      printf("%d\n",i);
   }else{
      printf("%d ",i);
   }
}

int main(){
   int j,k;
   while( scanf("%d %d",&j,&k) != EOF){

      queue<int> next;
      bool vis[10];
      memset(vis,0,sizeof(vis));
      memset(sol,-1,sizeof(sol));

      next.push(j);
      vis[j] = true;
      sol[j] = -1;
      int nx;
      while( !next.empty() ){
         nx = next.front();
         next.pop();
         if(nx == k)break;
         rep(i,10){
            if( graph[nx][i] && !vis[i]){
               vis[i] = true;
               sol[i] = nx;
               next.push(i);
            }
         }
      }

      print(k,1);
   }
   return 0;
}