#include <bits/stdc++.h>
char a[500010], b[500010], c[500010];
int nt[500010];
void kmp_nt(int m) {
  int i, j;
  i = 0;
  nt[0] = j = -1;
  while (i < m) {
    while (j != -1 && b[i] != b[j]) j = nt[j];
    if (b[i] == b[j] || j == -1) {
      i++;
      j++;
      nt[i] = j;
    }
  }
}
int main() {
  int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
  scanf("%s%s", a, b);
  int len1 = strlen(a);
  int len2 = strlen(b);
  if (len1 < len2)
    printf("%s\n", a);
  else {
    for (int i = 0; i < len1; i++) {
      if (a[i] == '0')
        cnt1++;
      else
        cnt2++;
    }
    for (int i = 0; i < len2; i++) {
      if (b[i] == '0')
        cnt3++;
      else
        cnt4++;
    }
    if (cnt1 < cnt3 || cnt2 < cnt4)
      printf("%s\n", a);
    else {
      kmp_nt(len2);
      int ans = len2 - nt[len2];
      for (int i = ans; i < len2; i++) {
        if (b[i] == '0') {
          cnt3--;
          cnt1--;
        } else {
          cnt4--;
          cnt2--;
        }
      }
      for (int i = 0; i < ans; i++) c[i] = b[i];
      int m, p, q;
      if (cnt3 == 0)
        p = 0;
      else
        p = cnt1 / cnt3;
      if (cnt4 == 0)
        q = 0;
      else
        q = cnt2 / cnt4;
      if ((p >= q && q != 0) || p == 0)
        m = q;
      else
        m = p;
      cnt1 -= m * cnt3;
      cnt2 -= m * cnt4;
      for (int i = 0; i < m; i++) printf("%s", c);
      for (int i = ans; i < len2; i++) printf("%c", b[i]);
      for (int i = 0; i < cnt1; i++) printf("0");
      for (int i = 0; i < cnt2; i++) printf("1");
      printf("\n");
    }
  }
  return 0;
}
