#include <bits/stdc++.h>
using namespace std;
char s[500001], t[500001];
long long nt[10000001], n, k, m;
long long c[2];
void kmp(long long x, char a[]) {
  int i, j;
  for (nt[0] = j = -1, i = 1; i < x; nt[i++] = j) {
    while (~j && a[j + 1] != a[i]) j = nt[j];
    if (a[j + 1] == a[i]) j++;
  }
}
int main() {
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(t);
  kmp(n, t);
  k = nt[n - 1];
  m = strlen(s);
  for (int i = 0; i < m; i++) c[s[i] - '0']++;
  for (int i = 0, j = 0; i < m; i++) {
    if (c[0] == 0)
      printf("1");
    else if (c[1] == 0)
      printf("0");
    else {
      printf("%c", t[j]);
      c[t[j] - '0']--;
      if (j == n - 1) j = nt[j];
      j++;
    }
  }
}
