#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    srand(time(NULL));
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    long long n;
    cin >> n;
  }
} __S;
long long a[10];
void add(string s, long long val) {
  for (long long i = 0; i < (long long)(s.size()); i++) {
    long long x = s[i] - '0';
    a[x] += val;
  }
}
void add(long long x, long long val) {
  while (x) {
    long long y = x % 10;
    a[y] += val;
    x /= 10;
  }
}
bool check(long long len, long long n, bool ok) {
  add(len, -1);
  for (long long i = 1; i < 10; i++) {
    if (a[i] > 0) ok = true;
  }
  for (long long i = 0; i < (long long)(10); i++) {
    n += a[i];
    if (a[i] < 0) ok = false;
  }
  add(len, 1);
  return min(ok, n == len);
}
int main(void) {
  string s;
  cin >> s;
  add(s, 1);
  if (s == "01" || s == "10") {
    cout << 0 << '\n';
    return 0;
  }
  string c;
  cin >> c;
  add(c, -1);
  long long len = s.size();
  while (!check(len, c.size(), (c[0] != '0'))) {
    len--;
  }
  add(len, -1);
  string ans = c;
  for (long long i = 0; i < (long long)(10); i++) {
    char c = i + '0';
    for (long long j = 0; j < (long long)(a[i]); j++) {
      ans += c;
    }
  }
  string m;
  for (long long i = 1; i < 10; i++) {
    if (a[i]) {
      a[i]--;
      char c = i + '0';
      m += c;
      break;
    }
  }
  if (m.size() == 0) {
    cout << ans << '\n';
    return 0;
  }
  for (long long i = 0; i < (long long)(11); i++) {
    string res = m;
    for (long long j = 0; j < 10; j++) {
      if (i == j) res += c;
      char c = j + '0';
      for (long long k = 0; k < (long long)(a[j]); k++) {
        res += c;
      }
    }
    if (i == 10) res += c;
    if (ans[0] == '0') ans = res;
    ans = min(ans, res);
  }
  cout << ans << '\n';
  return 0;
}
