#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double pi = 2 * acos(0.0);
long long a1, a2, a3, b1, b2, b3, c, c1, c2, c3, d, d1, d2, d3, d4, d5, e1, e2,
    e3, f, h, k, l, l1, l2, m, n, m1, m2, n1, n2, o, p, p1, p2, p3, p4, q, q1,
    q2, q3, q4, r, s, t, u, v, x, y, z, sum, mx = -1e15, mn = 1e15, flg, flg1,
                                             flg2, id1, id2, id3, id4, lim;
char str1[2000001], str2[2000001];
long long A[5], failure[2000001];
void buildFailureTable() {
  l2 = strlen(str2);
  failure[0] = failure[1] = 0;
  long long j;
  for (long long i = 2; i <= l2; i++) {
    j = failure[i - 1];
    while (true) {
      if (str2[j] == str2[i - 1]) {
        failure[i] = j + 1;
        break;
      }
      if (j == 0) {
        failure[i] = 0;
        break;
      }
      j = failure[j];
    }
  }
}
void solve() {
  n = strlen(str1);
  m = strlen(str2);
  if (n < m) {
    printf("%s\n", str1);
    return;
  }
  buildFailureTable();
  for (long long i = 0; i < n; i++) {
    A[(str1[i] - '0')]++;
  }
  id1 = 0;
  for (long long i = 0; i < n; i++) {
    d1 = (str2[id1] - '0');
    if (A[d1]) {
      printf("%lld", d1);
    } else {
      break;
    }
    A[d1]--;
    id1++;
    if (id1 == m) {
      id1 = failure[id1];
    }
  }
  while (A[0]) {
    printf("0");
    A[0]--;
  }
  while (A[1]) {
    printf("1");
    A[1]--;
  }
  printf("\n");
}
int main() {
  t = 1;
  while (t--) {
    scanf("%s%s", str1, str2);
    solve();
  }
  return 0;
}
