#include <bits/stdc++.h>
using namespace std;
vector<int> pref(string &s) {
  int n = s.size();
  vector<int> pr(n);
  for (int i = 1; i < n; ++i) {
    int j = pr[i - 1];
    while (j > 0 && s[i] != s[j]) j = pr[j - 1];
    if (s[i] == s[j]) ++j;
    pr[i] = j;
  }
  return pr;
}
int main() {
  int one = 0, zero = 0, j = 0;
  string s, t;
  cin >> s >> t;
  for (auto &it : s)
    if (it == '0')
      ++zero;
    else
      ++one;
  s = "";
  vector<int> p = pref(t);
  while (one > 0 && zero > 0) {
    bool isZero = t[j] == '0';
    if (isZero) {
      if (zero > 0) {
        --zero;
        ++j;
        s += '0';
      } else
        break;
    } else {
      if (one > 0) {
        --one;
        ++j;
        s += '1';
      } else
        break;
    }
    if (j == t.size()) j = min((int)t.size() - 1, (int)p.back());
  }
  while (one > 0 || zero > 0) {
    if (one > 0) --one, s += '1';
    if (zero > 0) --zero, s += '0';
  }
  cout << s;
  return 0;
}
