#include <bits/stdc++.h>
using namespace std;
string s, t;
int a[10];
int a1[10];
int b[10];
int b1[10];
bool ch(int l) {
  int l1 = l;
  for (int i = 0; i < 10; i++) b[i] = a[i];
  while (l1 > 0) {
    b[l1 % 10]--;
    l1 /= 10;
  }
  bool bb = 0;
  for (int i = 0; i < 10; i++)
    if (b[i] < 0) return 0;
  for (int i = 1; i < 10; i++)
    if (b[i] != 0) {
      bb = 1;
      break;
    }
  if (!bb && !(s.length() == 2 && b[0] == 1 && l == 1)) return 0;
  int r = 0;
  for (int i = 0; i < 10; i++) {
    if (a1[i] > b[i]) return 0;
    r += b[i];
  }
  return l == r;
}
int f(int x) {
  int r = 0;
  while (x > 0) {
    r++;
    x /= 10;
  }
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) a[s[i] - '0']++;
  for (int i = 0; i < t.length(); i++) a1[t[i] - '0']++;
  int l = -1;
  for (int i = 1; i <= 1000000; i++) {
    if (ch(i)) {
      l = i;
      break;
    }
  }
  if (l == -1) {
    cout << 0;
  } else {
    string res = "";
    for (int i = 0; i < 10; i++) b[i] -= a1[i];
    for (int i = 0; i < 10; i++) b1[i] = b[i];
    int in;
    if (1) {
      int maxx = 0;
      for (int i = 0; i < t.length(); i++) maxx = max(maxx, t[i] - '0');
      bool bb = 0;
      for (int i = 0; i < 10; i++) {
        if (i == t[0] - '0') {
          int j = 1;
          while (j < t.length() && t[j] - '0' == i) j++;
          if (j == t.length() || t[j] - '0' < i) {
            in = res.size();
            res += t;
          } else {
            bb = 1;
          }
        }
        while (b[i]--) res.push_back(i + '0');
        if (bb) {
          in = res.size();
          res += t;
          bb = 0;
        }
      }
    }
    int k = 0;
    for (int i = 0; i < res.length(); i++) {
      if (res[i] != '0' && (i < in || i >= in + t.length())) {
        k = i;
        break;
      }
    }
    if (res[0] == '0') {
      char c = res[k];
      string r1 = res.substr(0, k);
      string r2 = res.substr(k + 1, s.length() - (k + 1));
      res = "";
      res.push_back(c);
      res += r1 + r2;
      string res2 = t;
      for (int i = 0; i < 10; i++) b[i] = b1[i];
      for (int i = 0; i < 10; i++)
        while (b[i]--) res2.push_back(i + '0');
      if (res2[0] != '0') res = min(res, res2);
    }
    if (res[0] == '0') {
      res = "";
      res += t;
      for (int i = 0; i < 10; i++)
        while (b1[i]--) res.push_back(i + '0');
    }
    cout << res;
  }
  return 0;
}
