#include <bits/stdc++.h>
std::vector<int> prefix_function(const std::string& s) {
  int n = (int)s.length();
  std::vector<int> pi(static_cast<unsigned long>(n));
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  return pi;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::string s, t;
  std::cin >> s >> t;
  std::array<int, 2> s_decomposed = {0, 0};
  for (char c : s) {
    ++s_decomposed[c == '0' ? 0 : 1];
  }
  std::vector<int> t_prefix = prefix_function(t);
  int s_index = 0;
  while (s_decomposed.front() && s_decomposed.back()) {
    if (s_index == t.size()) {
      s_index = t_prefix.back();
    }
    if (t[s_index++] == '0') {
      std::cout << '0';
      --s_decomposed.front();
    } else {
      std::cout << '1';
      --s_decomposed.back();
    }
  }
  while (s_decomposed.front()) {
    std::cout << '0';
    --s_decomposed.front();
  }
  while (s_decomposed.back()) {
    std::cout << '1';
    --s_decomposed.back();
  }
}
