#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
int main() {
  string s, t;
  cin >> s >> t;
  if (s.size() < t.size()) {
    cout << s << "\n";
    return 0;
  }
  int n = t.size();
  vector<int> pref(n);
  for (int i = 1; i < n; ++i) {
    int j = pref[i - 1];
    while (j > 0 && t[i] != t[j]) {
      j = pref[j - 1];
    }
    if (t[i] == t[j]) j++;
    pref[i] = j;
  }
  string ans = "";
  int pos = 0;
  while (ans.size() < s.size()) {
    if (pos == t.size())
      pos = pref[pos - 1] - 1;
    else {
      ans.push_back(t[pos]);
    }
    pos++;
  }
  pair<int, int> ins, it;
  for (int i = 0; i < (int)s.size(); ++i) {
    if (s[i] == '0') {
      ins.first += 1;
    } else
      ins.second += 1;
  }
  for (int i = 0; i < (int)s.size(); ++i) {
    if (ans[i] == '0')
      it.first += 1;
    else
      it.second += 1;
  }
  pos = s.size() - 1;
  while (ins != it) {
    if (ans[pos] == '1' && it.second > ins.second) {
      ans[pos] = '0';
      it.second -= 1;
      it.first += 1;
    } else if (ans[pos] == '0' && it.first > ins.first) {
      ans[pos] = '1';
      it.second += 1;
      it.first -= 1;
    }
    pos -= 1;
  }
  cout << ans << "\n";
  return 0;
}
