#include <bits/stdc++.h>
using namespace std;
const int N = 12e5;
char s[N], s1[N];
int c[20];
int count(int x) {
  int a = 0;
  while (x) {
    a++;
    x /= 10;
  }
  return a;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  int n = strlen(s);
  for (int i = 0; i < n; i++) c[s[i] - '0']++;
  cin >> s;
  int l = strlen(s), cc = s[0] - '0';
  for (int i = 0; i < l; i++) c[s[i] - '0']--;
  for (int i = 1; i < l; i++) {
    if (s[i] < s[0]) {
      cc--;
      break;
    }
    if (s[i] > s[0]) break;
  }
  int m = n, t = 0;
  while (count(m) > t) m--, t++;
  while (m) {
    c[m % 10]--;
    m /= 10;
  }
  int cd = 11;
  for (int i = 1; i < 10; i++)
    if (c[i]) {
      cd = i;
      break;
    }
  s1[0] = cd + '0';
  c[cd]--;
  m = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < c[i]; j++) s1[m++] = i + '0';
    if (i == cc)
      for (int j = 0; j < l; j++) s1[m++] = s[j];
  }
  c[cd]++;
  if ((s[0] != '0' && strcmp(s, s1) <= 0) || cd > 9)
    cout << s, cc = -1;
  else
    cout << cd, c[cd]--;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < c[i]; j++) cout << i;
    if (i == cc) cout << s;
  }
  return 0;
}
