#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class RearrangeAndIncrement { public:
	vector <int> change(int X, int Y)
	{
		vector<int> ans;
		to_one(X, &ans);
		from_one(Y, &ans);

		vector<int> a;
		for (int i = 0; i < ans.size(); ++i) {
			a.push_back(ans[i]);
			for (;;) {
				auto it = find(ans.begin() + i + 1, ans.end(), ans[i]);
				if (it == ans.end()) break;
				i = it - ans.begin();
			}
		}
		cerr << "!!!" << a.size() << endl;
		return a;
	}

	void to_one(int X, vector<int>* ans)
	{
		ans->push_back(X);
		while (X != 1) {
			if (X % 10 != 0) {
				X += 10 - X % 10;
				ans->push_back(X);
			}

			vector<int> Xs = to_vec(X);
			sort(Xs.rbegin(), Xs.rend());
			X = to_int(Xs);
			ans->push_back(X);
		}
	}

	void from_one(int Y, vector<int>* ans)
	{
		vector<int> Ys = to_vec(Y);

		vector<int> Xs(Ys.size(), 0);
		Xs.back() = 1;

		one_to_base(to_int(Xs), ans);
		for (int i=Ys.size()-1; i>=0; --i) {
			if (count(Ys.begin(), Ys.begin() + i, 0) == i) {
				//     i
				// 00001
				// 0000Y
				if (i == 0) {
					Xs[i] = Ys[i];
					ans->push_back(to_int(Xs));
				}
				else {
					while (Xs[i] != Ys[i]) {
						for (int k = i - 1; k >= 1; --k) {
							Xs[0] = 9;
							ans->push_back(to_int(Xs));
							swap(Xs[0], Xs[k]);
							ans->push_back(to_int(Xs));
						}
						for (int k = i - 1; k >= 0; --k)
							Xs[k] = 0;
						Xs[i]++;
						ans->push_back(to_int(Xs));
					}
				}
			}
			else {
				//     i
				// 00001
				// ****Y
				Xs[0] = Ys[i];
				ans->push_back(to_int(Xs));
				rotate(Xs.begin(), Xs.begin() + 1, Xs.begin() + i + 1);
				ans->push_back(to_int(Xs));
			}
		}
	}

	void one_to_base(int B, vector<int>* ans)
	{
		int X = 1;
		while(X != B) {
			if (X == 1) {
				X = 10;
				ans->push_back(X);
			}
			else {
				vector<int> Xs = to_vec(X);
				for (int i = Xs.size() - 1; i >= 1; --i) {
					Xs[0] = 9;
					ans->push_back(to_int(Xs));
					sort(Xs.begin(), Xs.end());
					ans->push_back(to_int(Xs));
				}
				X *= 10;
				ans->push_back(X);
			}
		}
	}

	static vector<int> to_vec(int x) {
		vector<int> xs;
		while (x) {
			xs.push_back(x % 10);
			x /= 10;
		}
		return xs;
	}

	static int to_int(const vector<int>& xs) {
		int x = 0;
		int p = 1;
		for (int d : xs) {
			x += d * p;
			p *= 10;
		}
		return x;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, RearrangeAndIncrement().change(X, Y));}
int main(){

CASE(0)
	int X = 10234; 
	int Y = 1247; 
	int __[] = {10234, 1234, 1247 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int X = 10234; 
	int Y = 10248; 
	int __[] = {10234, 10244, 10248 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int X = 999997; 
	int Y = 1000001; 
	int __[] = {999997, 999998, 999999, 1000000, 1000001 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int X = 1000000; 
	int Y = 1000; 
	int __[] = {1000000, 1000 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int X = 1111111; 
	int Y = 1111232; 
	int __[] = {1111111, 1111122, 1111221, 1111232 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int X = 47; 
	int Y = 47; 
	int __[] = {47 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	int X = 1; 
	int Y = 900000000; 
	int __[] = { -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	int X = 111111111; 
	int Y = 900000000; 
	int __[] = { -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END

}
// END CUT HERE
