#include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
using namespace std;
const double EPS = 1e-10, PI = acos(-1);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string s, t;
  cin >> s >> t;
  vector<int> cnt(10);
  for (int i = 0; i < (int)s.size(); ++i) {
    cnt[s[i] - '0']++;
  }
  int keta = -1;
  for (int i = 1;; i++) {
    string tmp = to_string(i);
    vector<int> cnt2(10);
    for (int j = 0; j < tmp.size(); j++) {
      cnt2[tmp[j] - '0']++;
    }
    bool f = true;
    for (int j = 0; j < 10; j++) {
      if (cnt[j] < cnt2[j]) f = false;
    }
    if (f && s.size() - tmp.size() == i) {
      for (int j = 0; j < 10; j++) {
        cnt[j] -= cnt2[j];
      }
      keta = i;
      break;
    }
  }
  bool check = false;
  for (int i = 1; i < 10; i++) {
    if (cnt[i]) check = true;
  }
  if (!check) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < t.size(); i++) {
    cnt[t[i] - '0']--;
  }
  string ans1 = t;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < cnt[i]; j++) ans1 += (char)('0' + i);
  string ans = "#";
  if (ans1[0] != '0') ans = ans1;
  int h1 = 1;
  while (h1 < 10 && cnt[h1] == 0) h1++;
  int h2 = t[0] - '0';
  string ans2 = "", ans3 = "";
  if (h1 < 10) {
    ans2 += (char)(h1 + '0');
    ans3 += (char)(h1 + '0');
    cnt[h1]--;
    for (int i = 0; i < h2; i++) {
      for (int j = 0; j < cnt[i]; j++) {
        ans2 += (char)(i + '0');
        ans3 += (char)(i + '0');
      }
    }
    ans2 += t;
    for (int i = 0; i < cnt[h2]; i++) ans2 += (char)('0' + h2);
    for (int i = 0; i < cnt[h2]; i++) ans3 += (char)('0' + h2);
    ans3 += t;
    for (int i = h2 + 1; i < 10; i++) {
      for (int j = 0; j < cnt[i]; j++) {
        ans2 += (char)(i + '0');
        ans3 += (char)(i + '0');
      }
    }
    if (ans == "#") {
      ans = min({ans2, ans3});
    } else {
      ans = min({ans, ans2, ans3});
    }
  }
  cout << ans << endl;
  return 0;
}
