#include <bits/stdc++.h>
using namespace std;
inline long long fpow(long long n, long long k, int p = 998244353) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline long long inv(long long a, long long p = 998244353) {
  return fpow(a, p - 2, p);
}
inline long long addmod(long long a, long long val, long long p = 998244353) {
  {
    if ((a = (a + val)) >= p) a -= p;
  }
  return a;
}
inline long long submod(long long a, long long val, long long p = 998244353) {
  {
    if ((a = (a - val)) < 0) a += p;
  }
  return a;
}
inline long long mult(long long a, long long b, long long p = 998244353) {
  return (long long)a * b % p;
}
void computeLPSArray(string& pat, vector<int>& lps) {
  int i = 1, len = 0, M = pat.size();
  while (i < M) {
    if (pat[i] == pat[len]) {
      len++;
      lps[i] = len;
      i++;
    } else if (len != 0)
      len = lps[len - 1];
    else {
      lps[i] = 0;
      i++;
    }
  }
}
int cnt[2], cntpat[2];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, pat;
  cin >> s >> pat;
  int M = pat.size();
  vector<int> lps(M);
  computeLPSArray(pat, lps);
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '0')
      cnt[0]++;
    else
      cnt[1]++;
  }
  for (int i = 0; i < (int)pat.size(); i++) {
    if (pat[i] == '0')
      cntpat[0]++;
    else
      cntpat[1]++;
  }
  if (cnt[0] < cntpat[0] || cnt[1] < cntpat[1]) {
    cout << s << "\n";
    return 0;
  }
  vector<char> ans;
  for (int i = 0; i < M; i++) {
    ans.push_back(pat[i]);
    cnt[pat[i] - '0']--;
  }
  bool check = true;
  while (check) {
    int j = lps[M - 1];
    for (int i = j; i < M; i++) {
      if (cnt[pat[i] - '0']) {
        ans.push_back(pat[i]);
        cnt[pat[i] - '0']--;
      } else {
        check = false;
        break;
      }
    }
  }
  while (cnt[0] != 0 || cnt[1] != 0) {
    if (cnt[0]) {
      ans.push_back('0');
      cnt[0]--;
    }
    if (cnt[1]) {
      ans.push_back('1');
      cnt[1]--;
    }
  }
  for (auto x : ans) cout << x;
}
