#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9 + 7;
const long long Inf = 1e18 + 7;
const int maxn = 5e5 + 5;
const long long mod = 998244353;
int nxt[maxn], len1, len2;
char s1[maxn], s2[maxn];
int cnt[5];
void getNext(char s[], int len) {
  nxt[0] = -1;
  int i = 0, j = -1;
  while (i < len) {
    if (j == -1 || s[j] == s[i]) {
      nxt[++i] = ++j;
    } else
      j = nxt[j];
  }
}
int main() {
  scanf("%s %s", s1, s2);
  len1 = strlen(s1), len2 = strlen(s2);
  for (int i = 0; i < len1; ++i) cnt[s1[i] - '0']++;
  getNext(s2, len2);
  for (int i = 0; i < len2; ++i) {
    if (i == len1) break;
    int x = s2[i] - '0';
    if (cnt[x]) {
      cnt[x]--;
      s1[i] = s2[i];
    } else {
      if (cnt[1]) s1[i] = '1', cnt[1]--;
      if (cnt[0]) s1[i] = '0', cnt[0]--;
    }
  }
  int sta = nxt[len2];
  for (int i = len2; i < len1; ++i) {
    int x = s2[sta] - '0';
    if (cnt[x]) {
      cnt[x]--;
      s1[i] = x + '0';
      sta++;
      if (sta == len2) {
        sta = nxt[len2];
      }
    } else {
      while (cnt[0]) {
        cnt[0]--;
        s1[i++] = '0';
      }
      while (cnt[1]) {
        cnt[1]--;
        s1[i++] = '1';
      }
      break;
    }
  }
  cout << s1 << endl;
}
