#include <bits/stdc++.h>
using namespace std;
int prefix_function(string Z) {
  int n = (int)Z.length();
  vector<int> F(n);
  F[0] = 0;
  for (int i = 1; i < n; ++i) {
    int j = F[i - 1];
    while (j > 0 && Z[i] != Z[j]) j = F[j - 1];
    if (Z[i] == Z[j]) ++j;
    F[i] = j;
  }
  return F[n - 1];
}
void solve() {
  string s, t;
  cin >> s >> t;
  vector<int> arrs(2, 0), arrtn(2, 0);
  for (int i = 0; i < s.length(); i++) arrs[s[i] - '0']++;
  string ans = "";
  int len = prefix_function(t);
  string tnew = "";
  for (int i = 0; i < t.length() - len; i++) {
    tnew += t[i];
  }
  for (int i = 0; i < tnew.length(); i++) arrtn[tnew[i] - '0']++;
  vector<int> arre(2, 0);
  string ts = "";
  for (int i = 0; i < len; i++) {
    arre[t[i] - '0']++;
    ts += t[i];
  }
  while (arrs[0] >= arrtn[0] && arrs[1] >= arrtn[1]) {
    ans += tnew;
    arrs[0] -= arrtn[0];
    arrs[1] -= arrtn[1];
  }
  bool flag = true;
  while (true && len > 0) {
    for (int i = 0; i < len; i++) {
      if (arrs[t[i] - '0'] > 0) {
        ans += t[i];
        arrs[t[i] - '0']--;
      } else {
        flag = false;
        break;
      }
    }
    if (!flag) break;
  }
  while (arrs[1] != 0) {
    ans += '1';
    arrs[1]--;
  }
  while (arrs[0] != 0) {
    ans += '0';
    arrs[0]--;
  }
  cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
