#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 7;
inline int R() {
  int rt;
  scanf("%d", &rt);
  return rt;
}
char s[MAXN], t[MAXN];
int fl[MAXN];
int main() {
  scanf("%s%s", s + 1, t + 1);
  int ls = strlen(s + 1), lt = strlen(t + 1);
  int cnt1 = 0;
  for (int i = 1; i <= ls; ++i) cnt1 += s[i] - '0';
  int cnt0 = ls - cnt1;
  for (int i = 2; i <= lt; ++i) {
    int nf = fl[i - 1];
    while (nf && t[nf + 1] != t[i]) nf = fl[nf];
    if (t[nf + 1] == t[i]) fl[i] = nf + 1;
  }
  int sp1 = 0, ad1 = 0, sp0, ad0;
  for (int i = 1; i <= lt; ++i) sp1 += t[i] - '0';
  ad1 = sp1, sp0 = lt - sp1, ad0 = sp0;
  for (int i = 1; i <= fl[lt]; ++i)
    ad1 -= t[i] - '0', ad0 -= t[i] == '0' ? 1 : 0;
  if (cnt1 < sp1 || cnt0 < sp0) {
    printf("%s\n", s + 1);
    return 0;
  }
  cnt1 -= sp1, cnt0 -= sp0, printf("%s", t + 1);
  for (; cnt1 >= ad1 && cnt0 >= ad0; cnt1 -= ad1, cnt0 -= ad0)
    for (int i = fl[lt] + 1; i <= lt; ++i) putchar(t[i]);
  for (; cnt1; --cnt1) putchar('1');
  for (; cnt0; --cnt0) putchar('0');
  puts("");
  return 0;
}
