#include <bits/stdc++.h>
using namespace std;
string ans;
char jilu[1000010], rel[1000010];
int num[15], nnum[15];
int lll, lb;
bool ok, ooo;
bool panduan(int tmp) {
  int rel = lb - 1, ook = 0;
  for (int i = 0; i < 10; i++) {
    if (num[i] && i != 0) ook = 1;
    rel += num[i];
  }
  return rel == tmp && ook;
}
void dfs(int pos, int ed, int zhi) {
  if (ok) return;
  if (pos == ed) {
    if (panduan(zhi)) {
      lll = zhi;
      ok = 1;
    }
    return;
  }
  for (int i = 0; i < 10; i++)
    if (num[i]) {
      num[i]--;
      dfs(pos + 1, ed, zhi * 10 + i);
      num[i]++;
    }
}
int main() {
  scanf("%s%s", jilu, rel);
  int la = strlen(jilu);
  if (la == 2) {
    if (jilu[0] != '1')
      printf("%c\n", jilu[0]);
    else
      printf("%c\n", jilu[1]);
    return 0;
  }
  lb = strlen(rel);
  for (int i = 0; i < la; i++) num[jilu[i] - '0']++;
  for (int i = 1; i < lb; i++) num[rel[i] - '0']--;
  for (int i = 1; i <= 6; i++) {
    dfs(0, i, 0);
    if (ok) break;
  }
  num[rel[0] - '0']--;
  while (lll > 0) {
    num[lll % 10]--;
    lll /= 10;
  }
  for (int i = 0; i < 10; i++) {
    nnum[i] = num[i];
  }
  string tmpans;
  bool okk = 0;
  for (int i = 1; i < 10; i++) {
    if (num[i]) {
      okk = 1;
      num[i]--;
      tmpans += i + '0';
      break;
    }
  }
  int linshi = rel[0] - '0';
  bool da = 0;
  for (int i = 1; i < lb; i++) {
    if (rel[i] != rel[0]) {
      if (rel[i] > rel[0]) {
        da = 1;
      }
      break;
    }
  }
  for (int i = 0; i < 10; i++) {
    if (linshi == i && da == 0) {
      tmpans += rel;
    }
    while (num[i] > 0) {
      num[i]--;
      tmpans += i + '0';
    }
    if (linshi == i && da == 1) {
      tmpans += rel;
    }
  }
  if (rel[0] != '0') {
    string ans;
    ans += rel;
    for (int i = 0; i < 10; i++) {
      while (nnum[i] > 0) {
        nnum[i]--;
        ans += i + '0';
      }
    }
    if (okk)
      tmpans = min(ans, tmpans);
    else
      tmpans = ans;
  }
  cout << tmpans << endl;
}
