#include <bits/stdc++.h>
using namespace std;
char s[500005], t[500005];
int n, m, c0, c1, nxt[500005], u0, u1, uc0, uc1;
int main() {
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s), m = strlen(t);
  for (int i = 0; i < n; i++)
    if (s[i] == '0')
      c0++;
    else
      c1++;
  nxt[0] = -1;
  for (int k = 0, j = -1; k < m;)
    if (j == -1 || t[k] == t[j])
      nxt[++k] = ++j;
    else
      j = nxt[j];
  int len = nxt[m];
  for (int i = 0; i < m; i++)
    if (t[i] == '0')
      u0++;
    else
      u1++;
  for (int i = nxt[m]; i < m; i++)
    if (t[i] == '0')
      uc0++;
    else
      uc1++;
  if (c0 < u0 || c1 < u1) {
    puts(s);
    return 0;
  }
  c0 -= u0, c1 -= u1;
  int now = m;
  for (int i = 0; i < m; i++) s[i] = t[i];
  for (; c0 >= uc0 && c1 >= uc1;) {
    c0 -= uc0, c1 -= uc1;
    for (int j = 0; j < m - nxt[m]; j++) s[now + j] = t[j + nxt[m]];
    now += m - nxt[m];
  }
  for (int i = now; i < n; i++)
    if (c0)
      s[i] = '0', c0--;
    else
      s[i] = '1', c1--;
  puts(s);
}
