#include <bits/stdc++.h>
using namespace std;
int i, j, cnt = 0;
int nxt[500050] = {-1};
int ar[2] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t, ans = "";
  cin >> s >> t;
  for (int k = -1, i = 0; i < t.length();) {
    if (k == -1 || t[i] == t[k])
      nxt[++i] = ++k;
    else
      k = nxt[k];
  }
  for (i = 0; i < s.length(); i++) ar[s[i] - '0']++;
  j = 0;
  for (i = 0; i < s.length(); i++) {
    if (ar[t[j] - '0'] > 0)
      ans += t[j], ar[t[j] - '0']--;
    else {
      for (; i < s.length(); i++) ans += (t[j] == '0' ? '1' : '0');
    }
    j++;
    if (j == t.length()) j = nxt[t.length()];
  }
  cout << ans << '\n';
  return ~~(0 ^ 0 ^ 0);
}
