#include <bits/stdc++.h>
char S[600000], ans[600000];
int L, cnt0, cnt1, bord, tot;
const int P1 = 998244353, Q1 = 19260817;
const int P2 = 100000009, Q2 = 998244353;
int haL1, haL2, haR1, haR2, mul1 = 1, mul2 = 1;
int main() {
  scanf("%s", S);
  L = strlen(S);
  for (int i = 0; i < L; i++) (S[i] == '0' ? cnt0 : cnt1)++;
  scanf("%s", S);
  L = strlen(S);
  for (int i = 1; i < L; i++) {
    haL1 = (haL1 * static_cast<long long>(Q1) + S[i - 1]) % P1;
    haL2 = (haL2 * static_cast<long long>(Q2) + S[i - 1]) % P2;
    haR1 = (haR1 + S[L - i] * static_cast<long long>(mul1)) % P1;
    haR2 = (haR2 + S[L - i] * static_cast<long long>(mul2)) % P2;
    mul1 = static_cast<long long>(mul1) * Q1 % P1;
    mul2 = static_cast<long long>(mul2) * Q2 % P2;
    if (haL1 == haR1 && haL2 == haR2) bord = i;
  }
  for (int i = 0; i < L; i = (i == L - 1) ? bord : i + 1) {
    if (S[i] == '0') {
      if (!cnt0) break;
      cnt0--, ans[tot++] = '0';
    }
    if (S[i] == '1') {
      if (!cnt1) break;
      cnt1--, ans[tot++] = '1';
    }
  }
  while (cnt0--) ans[tot++] = '0';
  while (cnt1--) ans[tot++] = '1';
  puts(ans);
}
