#include <bits/stdc++.h>
using namespace std;
int lps[500001];
void solve() {
  string s, t, ans = "";
  cin >> s >> t;
  if (s.length() < t.length()) {
    cout << s;
    return;
  }
  int ones = 0, zers = 0, onet = 0, zert = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '1')
      ones++;
    else
      zers++;
  }
  for (int i = 0; i < t.length(); i++) {
    if (t[i] == '1')
      onet++;
    else
      zert++;
  }
  int i, j = -1;
  lps[0] = -1;
  for (i = 0; i < t.size(); i++) {
    while ((j >= 0) && (t[i] != t[j])) j = lps[j];
    lps[i + 1] = ++j;
  }
  string to_add = t.substr(lps[t.size()]);
  int new1 = 0, new0 = 0;
  for (int i = 0; i < to_add.length(); i++) {
    if (to_add[i] == '1')
      new1++;
    else
      new0++;
  }
  if (ones >= onet && zers >= zert) {
    ans += t;
    ones -= onet, zers -= zert;
  }
  while (ones >= new1 && zers >= new0) {
    ans += to_add;
    ones -= new1, zers -= new0;
  }
  for (int i = 0; i < ones; i++) ans += '1';
  for (int i = 0; i < zers; i++) ans += '0';
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
