#include <bits/stdc++.h>
using namespace std;
const long long M = 5e5 + 10;
const long long inf = 0x3f3f3f3f;
inline long long Read(void) {
  long long s = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    s = s * 10 + c - 48;
    c = getchar();
  }
  return s * f;
}
char s[M], t[M];
long long sums, sumt, nex[M];
signed main(void) {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  long long lens = strlen(s + 1);
  long long lent = strlen(t + 1);
  for (long long i = 1; i <= lens; i++) sums += (s[i] - '0');
  for (long long i = 1; i <= lent; i++) sumt += (t[i] - '0');
  if (sums < sumt || lens < lent) {
    for (long long i = 1; i <= lens; i++) putchar(s[i]);
    printf("\n");
    return 0;
  }
  for (long long i = 2, next = 0; i <= lent; i++) {
    while (next && t[next + 1] != t[i]) next = nex[next];
    if (t[next + 1] == t[i]) next++;
    nex[i] = next;
  }
  long long ans = lens + 1;
  for (long long i = 1, next = 0; i <= lens; i++) {
    if (sums && t[next + 1] == '1') {
      sums--;
      s[i] = '1';
      next++;
    } else if (t[next + 1] == '0') {
      next++;
      s[i] = '0';
    } else {
      ans = i;
      break;
    }
    if (next == lent) next = nex[next];
  }
  for (long long i = ans; i <= lens; i++) s[i] = '0';
  while (sums) {
    ans--;
    if (s[ans] == '1') sums++;
    sums--;
    s[ans] = '1';
  }
  for (long long i = 1; i <= lens; i++) putchar(s[i]);
  return 0;
}
