#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
#pragma GCC target "tune=native"
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
using namespace std;
int kmp_pre(char x[]) {
  int m = strlen(x);
  vector<int> pnext(m + 1);
  int i, j;
  j = pnext[0] = -1;
  i = 0;
  while (i < m) {
    while (-1 != j && x[i] != x[j]) j = pnext[j];
    pnext[++i] = ++j;
  }
  return pnext[m];
}
int main() {
  char s[500500], t[500500];
  scanf("%s", s);
  scanf("%s", t);
  int n = strlen(s), m = strlen(t);
  int q = kmp_pre(t);
  int zn = 0, zm = 0, zm2 = 0, um = 0, um2 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      zn++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (t[i] == '0') {
      zm++;
      if (i >= q) {
        zm2++;
      }
    } else {
      um++;
      if (i >= q) {
        um2++;
      }
    }
  }
  int r = 0;
  while (1) {
    r++;
    int zt = zm2 * (r - 1) + zm;
    int ut = um2 * (r - 1) + um;
    if (zt > zn || ut > (n - zn) || (zt + ut) > n) {
      r--;
      break;
    }
  }
  vector<char> res;
  for (int j = 0; j < q * min(r, 1); j++) {
    res.push_back(t[j]);
  }
  for (int i = 0; i < r; i++) {
    for (int j = q; j < m; j++) {
      res.push_back(t[j]);
    }
  }
  for (int i = 0; i < zn - min(r, 1) * (zm2 * (r - 1) + zm); i++) {
    res.push_back('0');
  }
  int l = (int)res.size();
  for (int i = 0; i < n - l; i++) {
    res.push_back('1');
  }
  for (int i = 0; i < n; i++) {
    s[i] = res[i];
  }
  printf("%s\n", s);
}
