#include <bits/stdc++.h>
using namespace std;
char p[500007], c[500007];
int a0, a1, len, anext[500007];
void GetNext() {
  int pLen = strlen(p);
  anext[0] = -1;
  int k = -1;
  int j = 0;
  while (j < pLen - 1) {
    if (k == -1 || p[j] == p[k]) {
      ++k;
      ++j;
      anext[j] = k;
    } else {
      k = anext[k];
    }
  }
}
int solve() {
  int i = 1, j = 0;
  while (p[i]) {
    if (j == -1 || p[i] == p[j]) {
      i++;
      j++;
    } else {
      j = anext[j];
    }
  }
  return j;
}
int main() {
  scanf("%s", c);
  scanf("%s", p);
  len = strlen(p);
  GetNext();
  int cf = solve();
  for (int i = 0; c[i]; i++) {
    if (c[i] == '1') {
      a1++;
    } else {
      a0++;
    }
  }
  for (int i = 0, j = 0; c[i]; i++) {
    if (a0 && a1) {
      if (j < len) {
        if (p[j] == '1')
          a1--;
        else
          a0--;
        printf("%c", p[j++]);
      } else {
        if (p[cf] == '1')
          a1--;
        else
          a0--;
        printf("%c", p[cf]);
        j = cf + 1;
      }
    } else
      break;
  }
  while (a0--) {
    printf("0");
  }
  while (a1--) {
    printf("1");
  }
  puts("");
}
