#include <bits/stdc++.h>
using namespace std;
int computeLPSArray(string pat) {
  int len = 0;
  int M = pat.length();
  int *lps = new int[M];
  lps[0] = 0;
  int i = 1;
  while (i < M) {
    if (pat[i] == pat[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
  return lps[M - 1];
}
long long largest_prefix_suffix(string &str) {
  size_t n = str.length();
  if (n < 2) {
    return 0;
  }
  long long len = 0;
  long long i = n / 2;
  while (i < n) {
    if (str[i] == str[len]) {
      len++;
      i++;
    } else {
      if (len == 0)
        i++;
      else
        len--;
    }
  }
  return len;
}
int main() {
  string s, t;
  cin >> s >> t;
  size_t s_zerosCount = count(s.begin(), s.end(), '0');
  size_t s_onesCount = s.length() - s_zerosCount;
  size_t t_zerosCount = count(t.begin(), t.end(), '0');
  size_t t_onesCount = t.length() - t_zerosCount;
  if (s_zerosCount < t_zerosCount || s_onesCount < t_onesCount)
    return puts(s.c_str());
  string output = t;
  s_zerosCount -= t_zerosCount;
  s_onesCount -= t_onesCount;
  t = t.substr(computeLPSArray(t));
  t_zerosCount = count(t.begin(), t.end(), '0');
  t_onesCount = t.length() - t_zerosCount;
  while (s_zerosCount >= t_zerosCount && s_onesCount >= t_onesCount) {
    output += t;
    s_zerosCount -= t_zerosCount;
    s_onesCount -= t_onesCount;
  }
  cout << output << string(s_zerosCount, '0') << string(s_onesCount, '1');
  return 0;
}
