#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 10;
char s[maxn], t[maxn];
int nextt[maxn];
void GetNext(char* p) {
  int i, j, k = 0;
  int lenp = strlen(p + 1);
  for (i = 2; i <= lenp; ++i) {
    nextt[i] = 0;
    while (k && p[k + 1] != p[i]) k = nextt[k];
    if (p[k + 1] == p[i]) ++k;
    nextt[i] = k;
  }
  return;
}
int sum[2];
int num1[2];
int num2[2];
int Min(int u, int v) { return u < v ? u : v; }
int main() {
  scanf("%s%s", s + 1, t + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) sum[s[i] - '0']++;
  n = strlen(t + 1);
  for (int i = 1; i <= n; i++) num2[t[i] - '0']++;
  if (num2[0] > sum[0] || num2[1] > sum[1]) {
    printf("%s", s + 1);
    return 0;
  }
  GetNext(t);
  int len = nextt[n] + 1;
  for (int i = len; i <= n; i++) num1[t[i] - '0']++;
  int cnt = 0;
  if (!num1[0])
    cnt = 1 + (sum[1] - num2[1]) / num1[1];
  else if (!num1[1])
    cnt = 1 + (sum[0] - num2[0]) / num1[0];
  else
    cnt = 1 + Min((sum[1] - num2[1]) / num1[1], (sum[0] - num2[0]) / num1[0]);
  printf("%s", t + 1);
  for (int i = 1; i < cnt; i++) {
    for (int j = len; j <= n; j++) printf("%c", t[j]);
  }
  for (int i = (cnt - 1) * num1[0] + num2[0]; i < sum[0]; i++) putchar('0');
  for (int i = (cnt - 1) * num1[1] + num2[1]; i < sum[1]; i++) putchar('1');
  return 0;
}
