#include <bits/stdc++.h>
using namespace std;
const long long ms = 2e5 + 100;
const long long mod1 = 1e9 + 7;
const long long mod2 = 1073676287;
const long long inf = 1e9;
const long long sigma = 30;
long long n, m, k, t = 1;
string s;
long long base1[1123456];
long long base2[1123456];
long long prime1 = 49;
long long prime2 = 71;
struct stringh {
  vector<pair<long long, long long> > a;
  stringh(){};
  stringh(string &s) {
    a.resize(s.size() + 1);
    a[0] = {0, 0};
    for (long long i = 0; i < s.size(); i++) {
      a[i + 1].first = (a[i].first * prime1 + s[i]) % mod1;
      a[i + 1].second = (a[i].second * prime2 + s[i]) % mod2;
    }
  }
  pair<long long, long long> get(long long l, long long r) {
    return {
        (a[r + 1].first - a[l].first * base1[r - l + 1] % mod1 + mod1) % mod1,
        (a[r + 1].second - a[l].second * base2[r - l + 1] % mod2 + mod2) %
            mod2};
  }
};
void init() {
  base1[0] = 1;
  base2[0] = 1;
  for (long long i = 1; i < 1123456; i++) {
    base1[i] = (base1[i - 1] * prime1) % mod1;
    base2[i] = (base2[i - 1] * prime2) % mod2;
  }
}
void solve() {
  string a, b;
  cin >> a >> b;
  init();
  stringh h(b);
  vector<long long> qt = {0, 0};
  for (auto first : a) {
    if (first == '0')
      qt[0]++;
    else
      qt[1]++;
  }
  long long best = 0;
  long long n = b.size();
  for (long long i = 1; i <= n; i++) {
    if (i - 1 >= n - 1) break;
    if (h.get(0, i - 1).first == h.get(n - i, n - 1).first &&
        h.get(0, i - 1).second == h.get(n - i, n - 1).second) {
      best = i;
    }
  }
  string ans;
  bool r = 1;
  for (long long i = 0; i < n; i++) {
    if (qt[b[i] - '0']) {
      ans += b[i];
      qt[b[i] - '0']--;
    } else {
      r = 0;
      break;
    }
  }
  if (!r) {
    while (qt[0]) ans += '0', qt[0]--;
    while (qt[1]) ans += '1', qt[1]--;
    cout << ans << '\n';
    return;
  }
  while (qt[0] && qt[1]) {
    bool r = 1;
    for (long long i = best; i < n; i++) {
      if (qt[b[i] - '0']) {
        ans += b[i];
        qt[b[i] - '0']--;
      } else {
        r = 0;
        break;
      }
    }
    if (!r) {
      break;
    }
  }
  while (qt[0]) ans += '0', qt[0]--;
  while (qt[1]) ans += '1', qt[1]--;
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (t--) {
    solve();
  }
}
