#include <bits/stdc++.h>
using namespace std;
char a[500001], b[500001];
int nxt[500000];
int c[2], la, lb;
int kmp() {
  nxt[0] = -1;
  if (lb == 0) {
    return 0;
  }
  int no = -1;
  for (int i = 1; i < lb; i++) {
    while (no != -1 && b[no + 1] != b[i]) {
      no = nxt[no];
    }
    if (b[no + 1] == b[i]) {
      no++;
    }
    nxt[i] = no;
  }
  return nxt[lb - 1] + 1;
}
void solve() {
  scanf("%s%s", a, b);
  c[0] = c[1] = 0;
  la = strlen(a);
  lb = strlen(b);
  for (int i = 0; i < la; i++) {
    c[a[i] - '0']++;
  }
  int add = kmp();
  for (int i = 0; i < lb; i++) {
    c[b[i] - '0']--;
    if (c[b[i] - '0'] < 0) {
      printf("%s\n", a);
      return;
    }
  }
  printf("%s", b);
  int c0 = 0, c1 = 0;
  for (int i = add; i < lb; i++) {
    if (b[i] == '0') {
      c0++;
    } else {
      c1++;
    }
  }
  while (c[0] >= c0 && c[1] >= c1) {
    c[0] -= c0;
    c[1] -= c1;
    for (int i = add; i < lb; i++) {
      putchar(b[i]);
    }
  }
  while (c[0]-- > 0) {
    putchar('0');
  }
  while (c[1]-- > 0) {
    putchar('1');
  }
  printf("\n");
}
int main() { solve(); }
