#include <bits/stdc++.h>
using namespace std;
char s[10000001], t[10000001];
long long nxt[10000001], n, k, m;
void kmp(long long x, char* a) {
  int i, j;
  for (nxt[0] = j = -1, i = 1; i < x; nxt[i++] = j) {
    while (~j && a[j + 1] != a[i]) j = nxt[j];
    if (a[j + 1] == a[i]) j++;
  }
}
long long c[2];
int main() {
  cin >> s;
  cin >> t;
  n = strlen(t);
  kmp(n, t);
  k = nxt[n - 1];
  m = strlen(s);
  for (int i = 0; i < m; i++) c[s[i] - '0']++;
  for (int i = 0, j = 0; i < m; i++) {
    if (!c[0])
      cout << 1;
    else if (!c[1])
      cout << 0;
    else {
      cout << t[j];
      c[t[j] - '0']--;
      if (j == n - 1) j = nxt[j];
      j++;
    }
  }
}
