#include <bits/stdc++.h>
using namespace std;
char s[1000050], ans[1000050], w[1000050];
int n, m;
int a[10];
int getLen(int x) {
  int p = 0;
  while (x > 0) {
    p++;
    x /= 10;
  }
  return p;
}
void relaxAns() {
  int L = 0;
  while (L < n && ans[L] == w[L]) L++;
  if (L == n) return;
  if (ans[L] < w[L]) return;
  for (int i = 0; i < n; i++) ans[i] = w[i];
  return;
}
void front() {
  if (s[0] == '0') return;
  for (int i = 0; i < m; i++) w[i] = s[i];
  int L = m;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < a[i]; j++) w[L++] = (char)('0' + i);
  relaxAns();
  return;
}
void solve(int x) {
  int p = 1;
  while (p < 10 && a[p] == 0) p++;
  if (p == 10) return;
  int L = 0;
  w[L++] = (char)('0' + p);
  a[p]--;
  for (int i = 0; i < x; i++)
    for (int j = 0; j < a[i]; j++) w[L++] = (char)('0' + i);
  for (int i = 0; i < m; i++) w[L++] = s[i];
  for (int i = x; i < 10; i++)
    for (int j = 0; j < a[i]; j++) w[L++] = (char)('0' + i);
  a[p]++;
  relaxAns();
  return;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) a[(s[i] - '0')]++;
  for (int k = max(1, n - 10); k < n; k++) {
    int x = k + getLen(k);
    if (x > n) break;
    if (x < n) continue;
    n = k;
    break;
  }
  int k = n;
  while (k > 0) {
    a[k % 10]--;
    k /= 10;
  }
  scanf("%s", s);
  m = strlen(s);
  for (int i = 0; i < m; i++) a[(s[i] - '0')]--;
  if (n == m) {
    printf("%s\n", s);
    return 0;
  }
  for (int i = 0; i < n; i++) ans[i] = 'A';
  ans[n] = (char)0;
  front();
  solve((int)(s[0] - '0'));
  solve((int)(s[0] - '0') + 1);
  printf("%s\n", ans);
  return 0;
}
