#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  long long hshL = 0, hshR = 0;
  long long x = 1;
  int maxI = 0;
  int br0 = 0;
  int br1 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] - '0' == 0)
      br0++;
    else
      br1++;
  }
  for (int i = 0; i < m - 1; i++) {
    hshL += (t[i] - '0' + 1) * x;
    if (hshL >= 1000000007) hshL %= 1000000007;
    hshR *= 27;
    hshR += t[m - i - 1] - '0' + 1;
    if (hshR >= 1000000007) hshR %= 1000000007;
    x *= 27;
    if (x >= 1000000007) x %= 1000000007;
    if (hshR == hshL) maxI = i + 1;
  }
  string suff = t.substr(maxI, m - maxI);
  while (t.size() < n) t += suff;
  cerr << maxI << " " << suff << endl;
  string rez = "";
  for (int i = 0; i < n; i++) {
    if (t[i] == '0') {
      if (br0 > 0)
        rez += '0', br0--;
      else
        rez += '1';
    } else {
      if (br1 > 0)
        rez += '1', br1--;
      else
        rez += '0';
    }
  }
  cout << rez;
  return 0;
}
