#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 2e18;
const int N = 1231234;
const int M = 11;
int n, m;
char s1[N], s2[N];
int sum[M];
int now[M];
int tmp[M];
bool cal_dig(int x) {
  memset(tmp, 0, sizeof(tmp));
  while (x) {
    tmp[x % 10]++;
    x /= 10;
  }
  for (int i = 0; i < 10; ++i)
    if (now[i] + tmp[i] > sum[i]) return false;
  return true;
}
int cal_len(int x) {
  int ans = 0;
  while (x) {
    ans++;
    x /= 10;
  }
  return ans;
}
vector<int> pre, ans, last;
int main() {
  while (scanf("%s%s", s1, s2) != EOF) {
    int i, j;
    n = strlen(s1);
    for (i = 0; i < n; ++i) sum[s1[i] - '0']++;
    m = strlen(s2);
    int zeom = 0;
    for (i = 0; i < m; ++i) {
      now[s2[i] - '0']++;
      ans.push_back(s2[i] - '0');
    }
    for (i = 1; i < m; ++i) {
      if (s2[i] != '0') break;
      zeom++;
    }
    int len = m;
    while (len + cal_len(len) != n || !cal_dig(len)) len++;
    for (i = 0; i < 10; ++i) now[i] += tmp[i];
    int f = 0;
    for (i = 1; i < m; ++i) {
      if (s2[i] > s2[0]) break;
      if (s2[i] < s2[0]) {
        f = 1;
        break;
      }
    }
    for (i = 0; i < 10; ++i) {
      int num = sum[i] - now[i];
      while (num > 0) {
        num--;
        if (!f) {
          if (i <= s2[0] - '0')
            pre.push_back(i);
          else
            last.push_back(i);
        } else {
          if (i < s2[0] - '0')
            pre.push_back(i);
          else
            last.push_back(i);
        }
      }
    }
    sort(pre.begin(), pre.end());
    sort(last.begin(), last.end());
    int zeo = 0;
    for (i = 0; i < pre.size(); ++i)
      if (pre[i] == 0) zeo++;
    if (zeo == pre.size()) {
      if (ans[0] == 0) {
        if (last.size()) printf("%d", last[0]);
        for (i = 0; i < zeo; ++i) printf("0");
        for (i = 0; i < ans.size(); ++i) printf("%d", ans[i]);
        for (i = 1; i < last.size(); ++i) printf("%d", last[i]);
        puts("");
      } else {
        int g = 0;
        if (last.size() && pre.size()) {
          if (last[0] < ans[0] || last[0] == ans[0] && zeo >= zeom) g = 1;
        }
        if (g) {
          printf("%d", last[0]);
          for (i = 0; i < zeo; ++i) printf("0");
          for (i = 0; i < ans.size(); ++i) printf("%d", ans[i]);
          for (i = 1; i < last.size(); ++i) printf("%d", last[i]);
          puts("");
          continue;
        }
        for (i = 0; i < ans.size(); ++i) printf("%d", ans[i]);
        for (i = 0; i < zeo; ++i) printf("0");
        for (i = 0; i < last.size(); ++i) printf("%d", last[i]);
        puts("");
      }
    } else {
      printf("%d", pre[zeo]);
      for (i = 0; i < zeo; ++i) printf("%d", pre[i]);
      for (i = zeo + 1; i < pre.size(); ++i) printf("%d", pre[i]);
      for (i = 0; i < ans.size(); ++i) printf("%d", ans[i]);
      for (i = 0; i < last.size(); ++i) printf("%d", last[i]);
      puts("");
    }
  }
}
