#include <bits/stdc++.h>
using namespace std;
string t, s;
int lens[1001000];
void Zfunction() {
  int n = s.size();
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      lens[i] = R - L;
      R--;
    } else {
      if (lens[i - L] < R - i + 1)
        lens[i] = lens[i - L];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        lens[i] = R - L;
        R--;
      }
    }
  }
}
int main() {
  cin >> t >> s;
  int siz = s.size();
  int cnt0 = 0, cnt1 = 0, cnt00 = 0, cnt11 = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '0')
      cnt0++;
    else
      cnt1++;
  }
  s = s + '$' + s;
  Zfunction();
  int pos = 0;
  for (int i = siz + 2; i < s.size(); i++) {
    if (lens[i] == s.size() - i) {
      pos = siz - (i - siz - 1);
      break;
    }
  }
  string ans = "";
  for (int i = 0; i < siz; i++) {
    if (s[i] == '0')
      cnt00++;
    else
      cnt11++;
  }
  if (cnt00 <= cnt0 && cnt11 <= cnt1) {
    for (int i = 0; i < siz; i++) ans += s[i];
    cnt0 -= cnt00;
    cnt1 -= cnt11;
  }
  cnt00 = 0, cnt11 = 0;
  for (int i = pos; i < siz; i++) {
    if (s[i] == '0')
      cnt00++;
    else
      cnt11++;
  }
  while (pos != siz && cnt00 <= cnt0 && cnt11 <= cnt1) {
    for (int i = pos; i < siz; i++) ans += s[i];
    cnt0 -= cnt00;
    cnt1 -= cnt11;
  }
  for (int i = 0; i < cnt0; i++) ans += '0';
  for (int i = 0; i < cnt1; i++) ans += '1';
  cout << ans << endl;
  return 0;
}
