#include <bits/stdc++.h>
using namespace std;
template <typename T>
void remin(T& a, const T& b) {
  if (b < a) a = b;
}
template <typename T>
void remax(T& a, const T& b) {
  if (b > a) a = b;
}
int occ[2], occ_t[2];
char S[500005], T[500005];
int kmp[500005];
int main(int argc, const char** argv) {
  int SS, ST, K;
  scanf("%s%s", S, T);
  SS = strlen(S);
  for (int k = 0; k < SS; ++k) {
    occ[S[k] - '0']++;
  }
  ST = strlen(T);
  for (int k = 0; k < ST; ++k) {
    occ_t[T[k] - '0']++;
  }
  int i = 0, j = 1, cnt = 0;
  bool ok;
  while (j < ST) {
    ok = false;
    while (T[i] == T[j]) {
      cnt++;
      kmp[j] = cnt;
      i++;
      j++;
      ok = true;
    }
    cnt = 0;
    i = 0;
    if (!ok) j++;
  }
  K = kmp[ST - 1];
  if (occ[0] >= occ_t[0] && occ[1] >= occ_t[1]) {
    printf("%s", T);
    occ[0] -= occ_t[0];
    occ[1] -= occ_t[1];
  }
  while (1) {
    for (int k = K; k < ST; ++k) {
      if (!occ[T[k] - '0']) {
        goto end;
      }
      printf("%c", T[k]);
      --occ[T[k] - '0'];
    }
  }
end:
  while (occ[0]) {
    printf("0");
    --occ[0];
  }
  while (occ[1]) {
    printf("1");
    --occ[1];
  }
  printf("\n");
  return 0;
}
