#include <bits/stdc++.h>
using namespace std;
int n, m, cnt1[3], cnt0[3], nxt[500010];
char s1[5000010], s2[5000010];
inline void getnext() {
  int j = 0;
  nxt[1] = 0;
  for (int i = 2; i <= m; ++i) {
    while (j && s2[j + 1] != s2[i]) j = nxt[j];
    if (s2[j + 1] == s2[i]) ++j;
    nxt[i] = j;
  }
}
int main() {
  scanf("%s", s1 + 1);
  scanf("%s", s2 + 1);
  n = strlen(s1 + 1);
  m = strlen(s2 + 1);
  getnext();
  for (int i = 1; i <= n; ++i) {
    if (s1[i] == '1')
      cnt1[1]++;
    else
      cnt0[1]++;
  }
  for (int i = 1; i <= m; ++i) {
    if (s2[i] == '1')
      cnt1[2]++;
    else
      cnt0[2]++;
  }
  int ji = 0;
  if (cnt1[2] != 0 && cnt0[2] != 0)
    ji = min(cnt1[1] / cnt1[2], cnt0[1] / cnt0[2]);
  else if (cnt1[2] == 0)
    ji = cnt0[1] / cnt0[2];
  else
    ji = cnt1[1] / cnt1[2];
  if (ji >= 1) {
    cout << s2 + 1;
    cnt1[1] -= cnt1[2];
    cnt0[1] -= cnt0[2];
  }
  int gg = ji, qwq = nxt[m];
  if (ji >= 1) {
    while (1) {
      int pd = 0;
      for (int i = qwq + 1; i <= m; ++i) {
        if (s2[i] == '1') {
          if (cnt1[1] > 0) {
            --cnt1[1];
            printf("1");
          } else {
            pd = 1;
            break;
          }
        } else {
          if (cnt0[1] > 0) {
            --cnt0[1];
            printf("0");
          } else {
            pd = 1;
            break;
          }
        }
      }
      if (pd) break;
    }
  }
  for (int i = 1; i <= cnt1[1]; ++i) printf("1");
  for (int i = 1; i <= cnt0[1]; ++i) printf("0");
  printf("\n");
  return 0;
}
