#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
vector<long long> zalgorithm(string s) {
  vector<long long> a(s.size());
  a[0] = s.size();
  long long i = 1, j = 0;
  while (i < s.size()) {
    while (i + j < s.size() && s[j] == s[i + j]) j++;
    a[i] = j;
    if (j == 0) {
      i++;
      continue;
    }
    long long k = 1;
    while (i + k < s.size() && k + a[k] < j) a[i + k] = a[k], k++;
    i += k;
    j -= k;
  }
  return a;
}
string S, T;
signed main() {
  cin.tie();
  ios_base::sync_with_stdio(false);
  cin >> S >> T;
  long long s0 = count((S).begin(), (S).end(), '0');
  long long s1 = S.size() - s0;
  long long t0 = count((T).begin(), (T).end(), '0');
  long long t1 = T.size() - t0;
  if (s0 < t0 || s1 < t1) {
    cout << S << endl;
    return 0;
  }
  vector<long long> z = zalgorithm(T);
  long long L = -1;
  for (long long i = T.size() - 1; i > 0; i--)
    if (z[i] == T.size() - i) {
      L = z[i];
    }
  if (L == -1) {
    long long tmp = 1001001001;
    if (t0) chmin(tmp, s0 / t0);
    if (t1) chmin(tmp, s1 / t1);
    string ans;
    for (long long i = 0; i < (tmp); i++) ans += T;
    for (long long i = 0; i < (s0 - tmp * t0); i++) ans += "0";
    for (long long i = 0; i < (s1 - tmp * t1); i++) ans += "1";
    cout << ans << endl;
    return 0;
  }
  string ans = T;
  s0 -= t0;
  s1 -= t1;
  long long z0;
  long long z1;
  z0 = count(T.begin() + L, T.end(), '0');
  z1 = T.size() - L - z0;
  long long tmp = 1001001001;
  if (z0 != 0) chmin(tmp, s0 / z0);
  if (z1 != 0) chmin(tmp, s1 / z1);
  for (long long i = 0; i < (tmp); i++) ans += T.substr(L, T.size() - L);
  s0 -= z0 * tmp;
  s1 -= z1 * tmp;
  for (long long i = 0; i < (s0); i++) ans += "0";
  for (long long i = 0; i < (s1); i++) ans += "1";
  cout << ans << endl;
  return 0;
}
