#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long N = 2e5 + 5;
const long double pi = 3.14159265359;
long long cnt[10], ucnt[10], x, f, con = 1, done, ty;
string a, b;
void build(long long len) {
  for (long long i = 0; i < 10; i++) ucnt[i] = cnt[i];
  x = len;
  while (x) ucnt[x % 10]--, x /= 10;
  for (long long i = 0; i < 10; i++)
    if (ucnt[i] < 0) return;
  for (long long i = 0; i < 10; i++) len -= ucnt[i];
  if (len - (long long)b.size()) return;
  f = 10;
  for (long long i = 9; i >= 1; i--)
    if (ucnt[i]) f = i;
  if (b[0] == '0') {
    cout << f;
    ucnt[f]--;
    for (long long i = 0; i < 10; i++) {
      if (i == b[0] - '0' && ty) cout << b;
      for (long long j = 0; j < ucnt[i]; j++) cout << i;
      if (i == b[0] - '0' && !ty) cout << b;
    }
  } else {
    string sa, sb;
    sa = b;
    for (long long i = 0; i < 10; i++)
      for (long long j = 0; j < ucnt[i]; j++) sa.push_back(i + '0');
    sb.push_back(f + '0');
    ucnt[f]--;
    for (long long i = 0; i < 10; i++) {
      if (i == b[0] - '0' && ty) sb = sb + b;
      for (long long j = 0; j < ucnt[i]; j++) sb.push_back(i + '0');
      if (i == b[0] - '0' && !ty) sb = sb + b;
    }
    cout << (sa < sb ? sa : sb);
  }
  done = 1;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> b;
  if (a == "01" || a == "10") {
    cout << "0\n";
    return 0;
  }
  for (long long i = 0; i < (long long)a.size(); i++) cnt[a[i] - '0']++;
  for (long long i = 0; i < (long long)b.size(); i++) {
    cnt[b[i] - '0']--;
    if (i && b[i] != b[i - 1] && con) {
      if (b[i] < b[i - 1]) ty = 1;
      con = 0;
    }
  }
  for (long long i = max(1LL, (long long)a.size() - 7);
       i <= (long long)a.size() - 1; i++) {
    build(i);
    if (done) return 0;
  }
  return 0;
}
