#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
char s[N], t[N], S[N];
int fail[N];
int main() {
  int n, m, i, j;
  scanf("%s%s", s, t);
  n = strlen(s), m = strlen(t);
  int cnt0 = 0, cnt1 = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '0') {
      cnt0++;
    } else {
      cnt1++;
    }
  }
  int c0 = 0, c1 = 0;
  for (i = 0; i < m; i++) {
    if (t[i] == '0') {
      c0++;
    } else {
      c1++;
    }
  }
  if (cnt0 < c0 || cnt1 < c1) {
    printf("%s", s);
    return 0;
  }
  fail[0] = fail[1] = 0;
  for (i = 1, j = 0; i < m; i++) {
    while (j > 0 && t[j] != t[i]) {
      j = fail[j];
    }
    if (t[j] == t[i]) {
      j++;
    }
    fail[i + 1] = j;
  }
  printf("%s", t);
  cnt0 -= c0, cnt1 -= c1;
  int p0 = 0, p1 = 0, h = 0;
  for (i = fail[m]; i < m; i++) {
    if (t[i] == '0') {
      p0++;
    } else {
      p1++;
    }
    S[h++] = t[i];
  }
  while (cnt0 >= p0 && cnt1 >= p1) {
    printf("%s", S);
    cnt0 -= p0, cnt1 -= p1;
  }
  while (cnt0 > 0) {
    printf("0");
    cnt0--;
  }
  while (cnt1 > 0) {
    printf("1");
    cnt1--;
  }
  return 0;
}
