#include <bits/stdc++.h>
using namespace std;
const int N = 500010, M = 500010;
int n, m;
char p[N], s[M];
int ne[N];
int A[2], B[2], C[2];
int main() {
  int len1, len2;
  scanf("%s", s + 1);
  len1 = strlen(s + 1);
  for (int i = 1; i <= len1; i++) {
    A[s[i] - '0']++;
  }
  scanf("%s", p + 1);
  len2 = strlen(p + 1);
  for (int i = 2, j = 0; i <= len2; i++) {
    while (j && p[i] != p[j + 1]) j = ne[j];
    if (p[i] == p[j + 1]) j++;
    ne[i] = j;
  }
  int maxlen = ne[len2];
  int cnt1x = 0, cnt0x = 0;
  for (int i = 1; i <= len2; i++) {
    B[p[i] - '0']++;
  }
  for (int i = maxlen + 1; i <= len2; i++) {
    C[p[i] - '0']++;
  }
  if (A[1] >= B[1] && A[0] >= B[0]) {
    printf("%s", p + 1);
    A[1] -= B[1];
    A[0] -= B[0];
    while (A[1] >= C[1] && A[0] >= C[0]) {
      printf("%s", p + maxlen + 1);
      A[1] -= C[1];
      A[0] -= C[0];
    }
  }
  while (A[0] > 0) {
    A[0]--;
    printf("0");
  }
  while (A[1] > 0) {
    A[1]--;
    printf("1");
  }
  return 0;
}
