#include <bits/stdc++.h>
using namespace std;
int n;
string s, t;
int fail[500100];
int a[500100];
int main() {
  cin >> s >> t;
  n = t.length();
  for (int i = 0; i < n; i++) a[i + 1] = t[i] - '0';
  for (int i = 1; i <= n; i++) {
    int k = fail[i - 1];
    while (k) {
      if (a[k + 1] == a[i]) {
        fail[i] = k + 1;
        break;
      }
      k = fail[k];
    }
    if (!fail[i]) fail[i] = (a[1] == a[i] && i != 1);
  }
  cerr << fail[n] << endl;
  int t0 = 0, t1 = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0')
      t0++;
    else
      t1++;
  }
  int s0 = 0, s1 = 0;
  for (int i = 0; i < t.length(); i++) {
    if (t[i] == '0')
      s0++;
    else
      s1++;
  }
  if (t0 < s0 || t1 < s1) return cout << s << endl, 0;
  cout << t;
  t0 -= s0;
  t1 -= s1;
  s0 = 0;
  s1 = 0;
  for (int i = fail[n]; i < n; i++) {
    if (t[i] == '0')
      s0++;
    else
      s1++;
  }
  cerr << s0 << ' ' << s1 << endl;
  while (t0 >= s0 && t1 >= s1) {
    cout << t.substr(fail[n], n - fail[n]);
    t0 -= s0;
    t1 -= s1;
  }
  while (t0) {
    cout << '0';
    t0--;
  }
  while (t1) {
    cout << '1';
    t1--;
  }
  cout << endl;
  return 0;
}
