#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2) {
      x = x * y;
      x %= 1000000007;
    }
    y = y * y;
    y %= 1000000007;
    b /= 2;
  }
  return x;
}
static char s[500005], t[500005];
static int lps[500005];
int main() {
  if (0) {
    freopen("C:/Users/gold/Desktop/sublime IO/input.txt", "r", stdin);
    freopen("C:/Users/gold/Desktop/sublime IO/output.txt", "w", stdout);
  }
  int T = 1;
  while (T--) {
    scanf("%s %s", s, t);
    int M = strlen(t);
    int len = 0;
    lps[0] = 0;
    int i = 1;
    while (i < M) {
      if (t[i] == t[len]) {
        len++;
        lps[i] = len;
        i++;
      } else {
        if (len != 0) {
          len = lps[len - 1];
        } else {
          lps[i] = 0;
          i++;
        }
      }
    }
    int mohib = lps[M - 1];
    int n = strlen(s);
    int one = 0, zero = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') {
        zero++;
      } else {
        one++;
      }
    }
    int f1 = 0, f0 = 0;
    for (int i = 0; i < M; i++) {
      if (t[i] == '0') {
        f0++;
      } else {
        f1++;
      }
    }
    if (f0 > zero || f1 > one) {
      printf("%s\n", s);
    } else {
      string ans = t;
      int curr = mohib;
      one -= f1;
      zero -= f0;
      for (int i = M; i < n; i++) {
        if (t[curr] == '0' && zero == 0) {
          break;
        }
        if (t[curr] == '1' && one == 0) {
          break;
        }
        ans += t[curr];
        if (t[curr] == '1') {
          one--;
        } else {
          zero--;
        }
        curr++;
        if (curr == M) {
          curr = mohib;
        }
      }
      while (zero > 0) {
        ans += '0';
        zero--;
      }
      while (one > 0) {
        ans += '1';
        one--;
      }
      printf("%s\n", ans.c_str());
    }
  }
  return 0;
}
