#include <bits/stdc++.h>
using namespace std;
void getZarr(string str, int Z[]) {
  int n = str.length();
  int L, R, k;
  L = R = 0;
  for (int i = 1; i < n; ++i) {
    if (i > R) {
      L = R = i;
      while (R < n && str[R - L] == str[R]) R++;
      Z[i] = R - L;
      R--;
    } else {
      k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < n && str[R - L] == str[R]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string second, t;
  cin >> second >> t;
  int n = t.length();
  int a[n];
  a[0] = 0;
  string tmp = t;
  getZarr(t, a);
  int c1 = 0, c2 = 0;
  for (int i = 0; i < second.length(); i++) {
    if (second[i] - '0')
      c1++;
    else
      c2++;
  }
  int t1 = 0, t2 = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] - '0')
      t1++;
    else
      t2++;
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == n - i) {
      mx = max(mx, a[i]);
    }
  }
  int r1 = 0, r2 = 0;
  string ad = "";
  for (int i = mx; i < n; i++) {
    if (t[i] - '0')
      r1++;
    else
      r2++;
  }
  if (mx != 0) ad = t.substr(mx, n - mx);
  string ans = "";
  if (mx == 0) {
    ad = t, r1 = t1, r2 = t2;
  }
  if (c1 >= t1 and c2 >= t2) {
    ans += t;
    c1 -= t1, c2 -= t2;
  }
  while (c1 >= r1 and c2 >= r2) {
    ans += ad;
    c1 -= r1, c2 -= r2;
  }
  while (c1) {
    ans += '1';
    c1--;
  }
  while (c2) {
    ans += '0';
    c2--;
  }
  cout << ans << "\n";
  return 0;
}
