#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 1e6 + 100;
int cnt[20];
char s[N];
char ss[N];
string str1, str2, str3, str4, ans;
int main() {
  scanf("%s", s);
  int len = strlen(s);
  for (int i = 0; i < len; ++i) ++cnt[s[i] - '0'];
  int k = 0;
  for (int i = 1; i <= 1e6; ++i) {
    if (len == i + (int)log10(i) + 1) {
      k = i;
      break;
    }
  }
  len -= (int)log10(k) + 1;
  while (k) {
    --cnt[k % 10];
    k /= 10;
  }
  cin >> str1;
  if (len == str1.size()) {
    cout << str1 << endl;
    return 0;
  }
  for (int i = 0; i < str1.size(); ++i) --cnt[str1[i] - '0'];
  str2 = str1;
  for (int i = 0; i < 10; ++i) {
    char ch = '0' + i;
    for (int j = 0; j < cnt[i]; ++j) {
      str2.push_back(ch);
    }
  }
  for (int i = 1; i < 10; ++i) {
    if (cnt[i]) {
      str3.push_back(i + '0');
      --cnt[i];
      break;
    }
  }
  for (int i = 0; i < 10; ++i) {
    char ch = '0' + i;
    for (int j = 0; j < cnt[i]; ++j) {
      str3.push_back(ch);
    }
  }
  str4 = str3;
  char ch = str1[0];
  {
    int pos = str3.size();
    for (int i = 1; i < str3.size(); ++i) {
      if (str3[i] >= ch) {
        pos = i;
        break;
      }
    }
    if (pos != str3.size())
      str3 = str3.substr(0, pos) + str1 + str3.substr(pos);
    else
      str3 = str3 + str1;
  }
  {
    int pos = 1;
    for (int i = (int)str4.size() - 1; i >= 1; --i) {
      if (str4[i] <= ch) {
        pos = i + 1;
        break;
      }
    }
    if (pos != str4.size())
      str4 = str4.substr(0, pos) + str1 + str4.substr(pos);
    else
      str4 = str4 + str1;
  }
  if (str2[0] != '0') ans = str2;
  if (str3[0] != '0') ans = str3;
  if (str4[0] != '0') ans = str4;
  if (str2[0] != '0') ans = min(str2, ans);
  if (str3[0] != '0') ans = min(str3, ans);
  if (str4[0] != '0') ans = min(str4, ans);
  cout << ans << endl;
  return 0;
}
