#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
const long double two = 2;
const long double INF = 2e9 + 100;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 100;
const long long nul = 0;
const long long SIZE = 1e6 * 3;
long long check(string s) {
  long long n = s.size();
  vector<long long> pr(n);
  for (long long i = 1; i < n; i++) {
    long long 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.back();
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long z = 0, o = 0, z1 = 0, o1 = 0, z2 = 0, o2 = 0;
  string s, t;
  cin >> s;
  cin >> t;
  string best;
  long long mx = check(t);
  for (long long i = mx; i < t.size(); ++i) best.push_back(t[i]);
  for (auto i : s) {
    if (i == '1')
      o++;
    else
      z++;
  }
  for (auto i : t) {
    if (i == '1')
      o1++;
    else
      z1++;
  }
  for (auto i : best) {
    if (i == '1')
      o2++;
    else
      z2++;
  }
  string ans;
  if (o1 <= o && z1 <= z)
    ans = t;
  else
    o1 = z1 = 0;
  long long cnt = 0;
  if (z2 > 0 && o2 > 0) {
    cnt = min((o - o1) / o2, (z - z1) / z2);
  }
  for (long long i = 0; i < cnt; i++) {
    o1 += o2;
    z1 += z2;
    ans += best;
  }
  for (long long i = o1; i < o; i++) ans += '1';
  for (long long i = z1; i < z; i++) ans += '0';
  cout << ans << endl;
}
