#include <bits/stdc++.h>
void build_kmp(int *fail, char *p) {
  int len = strlen(p);
  int j = fail[0] = -1, i;
  for (i = 1; i <= len; ++i) {
    while (j >= 0 && p[j] != p[i - 1]) j = fail[j];
    fail[i] = ++j;
  }
}
char s[500005], t[500005], ans[500005];
int slen, tlen, anslen, cnt0, cnt1;
int fail[500005];
int main() {
  register int i;
  scanf("%s\n%s", s, t);
  slen = strlen(s), tlen = strlen(t);
  if (slen < tlen) return puts(s) & 0;
  build_kmp(fail, t);
  for (i = 0; i < slen; ++i) cnt1 += (s[i] == '1'), cnt0 += (s[i] == '0');
  int pos = 1;
  for (i = 0; i < slen; ++i) {
    if ((t[pos - 1] == '1' ? --cnt1 : --cnt0) < 0) {
      cnt1 += (t[pos - 1] == '1'), cnt0 += (t[pos - 1] == '0');
      for (i = 0; i < cnt1; ++i) ans[anslen++] = '1';
      for (i = 0; i < cnt0; ++i) ans[anslen++] = '0';
      return puts(ans) & 0;
    }
    ans[anslen++] = t[pos - 1];
    pos = (pos != tlen ? pos + 1 : fail[pos] + 1);
  }
  puts(ans);
  return 0;
}
