#include <bits/stdc++.h>
using namespace std;
const int MX = 5e5 + 10, MD = 1e9 + 7;
long long n, m, a[MX], ans, tmp, f[MX], cnt1, cnt0, cntt11, cntt10, cntt21,
    cntt20;
string s, t, t2, t1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1')
      cnt1++;
    else
      cnt0++;
  }
  n = t.size();
  long long curr = 0;
  for (int i = 2; i <= n; i++) {
    curr = f[i - 1];
    while (curr && t[curr] != t[i - 1]) curr = f[curr];
    if (t[curr] == t[i - 1]) f[i] = curr + 1;
  }
  for (int i = f[n]; i < n; i++) {
    t2 += t[i];
  }
  for (int i = 0; i < f[n]; i++) {
    t1 += t[i];
  }
  for (int i = 0; i < t1.size(); i++) {
    if (t1[i] == '1')
      cntt11++;
    else
      cntt10++;
  }
  for (int i = 0; i < t2.size(); i++) {
    if (t2[i] == '1')
      cntt21++;
    else
      cntt20++;
  }
  if (cntt10 <= cnt0 && cntt11 <= cnt1) {
    cout << t1;
    cnt1 -= cntt11;
    cnt0 -= cntt10;
  }
  while (cntt21 <= cnt1 && cntt20 <= cnt0) {
    cout << t2;
    cnt1 -= cntt21;
    cnt0 -= cntt20;
  }
  for (int i = 0; i < cnt1; i++) cout << '1';
  for (int i = 0; i < cnt0; i++) cout << '0';
}
