#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000, ss = 8 * 1024;
int n, m, k[10];
char aa[1000001], bb[1000001];
string s, t, ans = "";
void f1(int a[10], string b) {
  if (t[0] == '0') return;
  string q;
  q = "";
  q += t;
  for (long long i = 0; i < 10; i++)
    for (long long j = 0; j < a[i]; j++) q += char(i + '0');
  ans = min(ans, q);
}
void fmin1(int a[10], string b) {
  string q = "";
  for (int i = 1; i < 10; i++) {
    if (a[i]) {
      q += char(i + '0');
      a[i]--;
      break;
    }
  }
  char pp = '0';
  for (long long i = 0; i < (int)t.size(); i++)
    if (t[i] != t[0]) {
      pp = t[i];
      break;
    }
  if (q == "") return;
  bool ok = true;
  for (long long i = 0; i < 10; i++) {
    for (long long j = 0; j < a[i]; j++) {
      if (ok == true && (i > t[0] - '0' || (i == t[0] - '0' && pp - '0' < i))) {
        q += t;
        ok = false;
      }
      q += char(i + '0');
    }
  }
  if (ok) q += t;
  ans = min(ans, q);
}
void f2(int a[10], string k, int j) {
  string c = "", q = "";
  for (int nu = 0; nu < (int)t.size() - j; nu++) {
    c += t[nu];
    a[t[nu] - '0']--;
    if (a[t[nu] - '0'] < 0) {
      return;
    }
  }
  for (int i = 1; i < 10; i++) {
    if (a[i]) {
      q += char(i + '0');
      a[i]--;
      break;
    }
  }
  for (long long i = 0; i < 10; i++)
    for (long long j = 0; j < a[i]; j++) q += char(i + '0');
  q += c;
  if (q[0] == '0') return;
  ans = min(ans, q);
}
void fc(int len) {
  string p = "";
  while (len) {
    p += char(len % 10 + '0');
    k[len % 10]--;
    len /= 10;
  }
  reverse(p.begin(), p.end());
  for (long long i = 0; i < (int)t.size(); i++) {
    k[t[i] - '0']--;
    if (k[t[i] - '0'] < 0) return;
  }
  f1(k, p);
  fmin1(k, p);
}
int main() {
  scanf("%s%s", aa, bb);
  s = aa;
  t = bb;
  n = (int)s.size(), m = (int)s.size();
  for (long long i = 0; i < n; i++) {
    ans += "9";
    k[s[i] - '0']++;
  }
  if (n == 2 && k[0] == 1 && k[1] == 1) {
    printf("0");
    return 0;
  }
  for (int len = 1; len <= n; len++) {
    long long p = len, k = 0;
    while (p) {
      k++;
      p /= 10;
    }
    if (k + len == n) {
      fc(len);
    }
  }
  printf("%s", ans.c_str());
  return 0;
}
