#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int ds[15], dt[15], da[15], dr[15];
int ted = 1;
string s, t;
bool check(int number) {
  int tmp = number;
  memset(da, 0, sizeof da);
  while (tmp) {
    da[tmp % 10]++;
    tmp /= 10;
  }
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    dr[i] = ds[i] - dt[i] - da[i];
    if (dr[i] < 0) return false;
    sum = sum + dr[i] + dt[i];
  }
  if (sum != number) return false;
  if (number == 1) return true;
  if (dr[0] > 0) {
    for (int i = 1; i < 10; i++)
      if (dr[i] > 0) return true;
  }
  if (t[0] != 0) return true;
  return false;
}
void write(int num) {
  if (dr[num] == 0) {
    cout << t;
    return;
  }
  if ((int)t.size() == 1) {
    cout << t;
    while (dr[num]--) cout << num;
    return;
  }
  int pos = 0;
  while (t[pos] - '0' == num) pos++;
  if (pos == (int)t.size() || t[pos] - '0' < num) {
    cout << t;
    while (dr[num]--) cout << num;
    return;
  }
  while (dr[num]--) cout << num;
  cout << t;
}
bool can(int num) {
  if (t[0] - '0' == 0) return false;
  if (t[0] - '0' > num) return false;
  if (t[0] - '0' < num) return true;
  int pos = 0, op = 0, hh = 0;
  while (t[pos] - '0' == num) {
    pos++;
    hh++;
  }
  for (int i = 0; i < 10; i++) {
    op = 0;
    while (t[pos] - '0' == i) {
      pos++;
      op++;
    }
    if (op == dr[i] - (i == t[pos] - '0') * hh) continue;
    return (op > dr[i] - (i == t[pos] - '0') * hh);
  }
  return (pos == (int)t.size()) ? true : (num >= t[pos] - '0');
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> t;
  for (int i = 0; i < (int)s.size(); i++) ds[s[i] - '0']++;
  for (int i = 0; i < (int)t.size(); i++) dt[t[i] - '0']++;
  while (true) {
    if (check(ted)) break;
    ted++;
  }
  cout << endl;
  if (ted == 1 && (dr[0] == 1 || dt[0] == 1)) {
    cout << 0 << endl;
    exit(0);
  }
  int tmp;
  for (tmp = 1; tmp < 10; tmp++) {
    if (dr[tmp] > 0) break;
  }
  if (dr[tmp] == 0 || can(tmp)) {
    cout << t;
    for (int i = 0; i < 10; i++) {
      while (dr[i]--) cout << i;
    }
    cout << endl;
    exit(0);
  }
  cout << tmp;
  dr[tmp]--;
  ted--;
  ted = ted - t.size();
  for (int i = 0; i < 10; i++) {
    if (i == t[0] - '0') {
      write(i);
      continue;
    }
    while (dr[i]--) cout << i;
  }
  cout << endl;
  return 0;
}
