#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp& x) {
  x = 0;
  char tmp;
  bool key = 0;
  for (tmp = getchar(); !isdigit(tmp); tmp = getchar()) key = (tmp == '-');
  for (; isdigit(tmp); tmp = getchar()) x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
const int N = 500010;
char t[N], s[N];
int nex[N];
int n, num[2], m;
int main() {
  scanf("%s", t + 1);
  n = strlen(t + 1);
  for (int i = (1); i <= (n); ++i) ++num[t[i] - '0'];
  m = n;
  scanf("%s", t + 1);
  n = strlen(t + 1);
  nex[0] = -1;
  for (int i = 2, j = 0; i <= n; ++i) {
    while (j >= 0 && t[i] != t[j + 1]) j = nex[j];
    nex[i] = ++j;
  }
  for (int i = 1, j = 0; i <= m; ++i) {
    while (j >= 0 && num[t[j + 1] - '0'] == 0) j = nex[j];
    int v;
    if (j == -1) {
      v = num[0] ? 0 : 1;
    } else
      v = t[j + 1] - '0', ++j;
    s[i] = v + '0';
    --num[v];
    if (j == n) j = nex[j];
  }
  for (int i = 1; i <= m; ++i) putchar(s[i]);
  puts("");
  return 0;
}
