#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s1[maxn], s2[maxn];
int cnta[256], cntb[256];
int nxt[maxn];
int main() {
  string ans;
  scanf("%s%s", s1 + 1, s2 + 1);
  int lena = strlen(s1 + 1), lenb = strlen(s2 + 1);
  for (int i = 1; i <= lena; i++) cnta[s1[i] - '0']++;
  for (int i = 1; i <= lenb; i++) cntb[s2[i] - '0']++;
  if (cnta[1] >= cntb[1] && cnta[0] >= cntb[0]) {
    ans = string(s2 + 1);
    cnta[0] -= cntb[0];
    cnta[1] -= cntb[1];
  }
  for (int i = 2, j = 0; i <= lenb; i++) {
    while (s2[i] != s2[j + 1] && j) j = nxt[j];
    if (s2[i] == s2[j + 1]) j++;
    nxt[i] = j;
  }
  while (cnta[1] && cnta[0]) {
    for (int i = nxt[lenb] + 1; i <= lenb; i++) {
      if (cnta[s2[i] - '0']) {
        ans += s2[i];
        cnta[s2[i] - '0']--;
      } else {
        goto ed;
      }
    }
  }
ed:;
  while (cnta[0]--) ans += '0';
  while (cnta[1]--) ans += '1';
  cout << ans;
  return 0;
}
