#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 510000;
char s[N], t[N];
int n0, n1, n, m, c0, c1;
int m0, m1;
int kmpnext[N];
char ans[N];
void getnext(char t[], int m) {
  int i, j;
  i = 0, j = 1;
  kmpnext[1] = 0;
  while (j <= m)
    if (i == 0 || t[i] == t[j]) {
      ++i, ++j;
      kmpnext[j] = i;
    } else
      i = kmpnext[i];
}
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      n0++;
    else
      n1++;
  for (int i = 1; i <= m; i++)
    if (t[i] == '0')
      m0++;
    else
      m1++;
  if (n0 < m0 || n1 < m1) {
    printf("%s\n", s + 1);
    return 0;
  }
  getnext(t, m);
  for (int i = kmpnext[m + 1]; i <= m; i++)
    if (t[i] == '0')
      c0++;
    else
      c1++;
  int nn = m;
  for (int i = 1; i <= m; i++) ans[i] = t[i];
  n0 -= m0, n1 -= m1;
  while (1) {
    if (n0 < c0 || n1 < c1) break;
    for (int i = kmpnext[m + 1]; i <= m; i++)
      if (t[i] == '0')
        ans[++nn] = '0';
      else
        ans[++nn] = '1';
    n0 -= c0, n1 -= c1;
  }
  for (; n0 + n1 > 0;)
    if (n0 > 0)
      ans[++nn] = '0', n0--;
    else
      ans[++nn] = '1', n1--;
  printf("%s\n", ans + 1);
  return 0;
}
