#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
char s[N], t[N];
int n0, n1, nxt[N], m0, m1, r0, r1;
int main() {
  scanf("%s%s", s + 1, t + 1);
  int L = strlen(s + 1);
  for (int i = 1; i <= L; i++) {
    if (s[i] == '0')
      n0++;
    else
      n1++;
  }
  int L1 = strlen(t + 1);
  int j = 0;
  for (int i = 1; i < L1; i++) {
    while (t[i + 1] != t[j + 1] && j) j = nxt[j];
    if (t[i + 1] == t[j + 1]) {
      nxt[i + 1] = ++j;
    } else
      nxt[i + 1] = 0;
  }
  int r = nxt[L1];
  for (int i = 1; i <= L1; i++) {
    if (t[i] == '0')
      m0++;
    else
      m1++;
    if (i > r) {
      if (t[i] == '0')
        r0++;
      else
        r1++;
    }
  }
  if (n1 < m1 || n0 < m0)
    printf("%s", s + 1);
  else {
    printf("%s", t + 1);
    n1 -= m1;
    n0 -= m0;
    while (n1 >= r1 && n0 >= r0) {
      printf("%s", t + r + 1);
      n1 -= r1;
      n0 -= r0;
    }
    while (n1--) printf("1");
    while (n0--) printf("0");
  }
  return 0;
}
