#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, lg = 20;
vector<int> build_fail(string &pat) {
  int len = 0;
  vector<int> fail(pat.size());
  fail[0] = 0;
  for (int i = 1; i < pat.size(); i++) {
    while (len && pat[i] != pat[len]) len = fail[len - 1];
    if (pat[i] == pat[len]) len++;
    fail[i] = len;
  }
  return fail;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, pat, tmp, ans = "";
  cin >> s >> pat;
  auto fail = build_fail(pat);
  tmp = pat;
  int cnt11 = 0, cnt1 = 0, cnt0 = 0, cnt00 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1')
      cnt11++;
    else
      cnt00++;
  }
  for (int i = pat.size(); i < s.size(); i++) {
    if (fail[pat.size() - 1] == 0)
      tmp.push_back(pat[fail[pat.size() - 1] + (i - pat.size()) % pat.size()]);
    else
      tmp.push_back(
          pat[fail[pat.size() - 1] +
              (i - pat.size()) % ((int)pat.size() - fail[pat.size() - 1])]);
  }
  for (int i = 0; i < tmp.size(); i++) {
    if (tmp[i] == '1' && cnt1 == cnt11)
      break;
    else if (tmp[i] == '0' && cnt0 == cnt00)
      break;
    if (tmp[i] == '1') {
      cnt1++;
      ans.push_back('1');
    } else if (tmp[i] == '0') {
      cnt0++;
      ans.push_back('0');
    }
  }
  int cnt = cnt11 - cnt1;
  while (cnt--) ans.push_back('1');
  cnt = cnt00 - cnt0;
  while (cnt--) ans.push_back('0');
  cout << ans << '\n';
  return 0;
}
