#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
char a[N], b[N], c[N];
int ope, opf, opg, pay, pby, thb, tha, som[N];
void ano();
int main() {
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  ope = strlen(a + 1);
  opf = strlen(b + 1);
  ano();
  for (int i = 1; i <= ope; i++)
    if (a[i] == '1')
      pay++;
    else
      pby++;
  for (int i = 1; i <= opf; i++)
    if (b[i] == '1')
      pay--;
    else
      pby--;
  if (pay < 0 || pby < 0) {
    printf("%s\n", a + 1);
    exit(0);
  }
  strcpy(c + 1, b + som[opf + 1]);
  opg = strlen(c + 1);
  for (int i = 1; i <= opg; i++)
    if (c[i] == '1')
      thb++;
    else
      tha++;
  printf("%s", b + 1);
  while (pay >= thb && pby >= tha) {
    printf("%s", c + 1);
    pay -= thb;
    pby -= tha;
  }
  while (pay) {
    printf("1");
    pay--;
  }
  while (pby) {
    printf("0");
    pby--;
  }
  printf("\n");
  return 0;
}
void ano() {
  int k = 0;
  som[1] = 0;
  int j = 1;
  while (j <= opf) {
    if (!k || b[j] == b[k]) {
      if (b[++j] == b[++k])
        som[j] = som[k];
      else
        som[j] = k;
    } else
      k = som[k];
  }
  return;
}
