#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int l1, l2, cnt;
int cnt1[2], cnt2[2], cnt3[2];
char str1[maxn], str2[maxn];
int nex[maxn];
void getnext() {
  int j = 0;
  nex[0] = -1;
  int k = -1;
  while (j < l2) {
    if (k == -1 || str2[k] == str2[j]) {
      k++;
      nex[++j] = k;
    } else
      k = nex[k];
  }
}
int main() {
  scanf("%s%s", str1, str2);
  l1 = strlen(str1);
  l2 = strlen(str2);
  getnext();
  int tmp = nex[l2];
  if (tmp == -1) tmp = 0;
  for (int i = 0; i < l1; ++i) ++cnt1[str1[i] - '0'];
  for (int i = 0; i < tmp; ++i) ++cnt2[str2[i] - '0'];
  for (int i = tmp; i < l2; ++i) ++cnt3[str2[i] - '0'];
  if (cnt1[0] >= cnt2[0] + cnt3[0] && cnt1[1] >= cnt2[1] + cnt3[1]) {
    cnt1[0] -= cnt2[0] + cnt3[0];
    cnt1[1] -= cnt2[1] + cnt3[1];
    ++cnt;
    int t;
    if (cnt3[0] && cnt3[1])
      t = min(cnt1[0] / cnt3[0], cnt1[1] / cnt3[1]);
    else if (cnt3[0] && !cnt3[1])
      t = cnt1[0] / cnt3[0];
    else
      t = cnt1[1] / cnt3[1];
    cnt += t;
    cnt1[0] -= cnt3[0] * t;
    cnt1[1] -= cnt3[1] * t;
  }
  if (cnt) {
    for (int i = 0; i < l2; ++i) printf("%c", str2[i]);
    --cnt;
  }
  for (int i = 0; i < cnt; ++i)
    for (int j = tmp; j < l2; ++j) printf("%c", str2[j]);
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < cnt1[i]; ++j) printf("%c", '0' + i);
  puts("");
  return 0;
}
