#include <bits/stdc++.h>
const int MAX = (const int)(1e5 + 11);
using namespace std;
string A, B;
vector<int> z_function(const string &s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
static void solve(std::int32_t test) {
  cin >> A >> B;
  if (A.length() < B.length()) {
    cout << A;
    return;
  }
  const auto &z = z_function(B);
  int mx = -1;
  for (int i = 0; i < z.size(); ++i) {
    if (i + z[i] < z.size()) continue;
    if (mx == -1 || z[mx] < z[i]) mx = i;
  }
  int c00 = 0, c01 = 0;
  for (auto ch : A)
    if (ch == '0')
      c00++;
    else
      c01++;
  int c10 = 0, c11 = 0;
  for (auto ch : B)
    if (ch == '0')
      c10++;
    else
      c11++;
  string result;
  if (mx == -1) {
    while (c00 >= c10 && c01 >= c11) {
      c00 -= c10;
      c01 -= c11;
      result += B;
    }
  } else {
    result = B;
    string pre = B.substr(z[mx], B.size() - z[mx]);
    int p0 = 0, p1 = 0;
    for (auto ch : pre)
      if (ch == '0')
        p0++;
      else
        p1++;
    if (c00 >= c10 && c01 >= c11) {
      c00 -= c10;
      c01 -= c11;
    } else {
      cout << A;
      return;
    }
    while (c00 >= p0 && c01 >= p1) {
      c00 -= p0;
      c01 -= p1;
      result += pre;
    }
  }
  for (int i = 0; i < c00; ++i) result += '0';
  for (int i = 0; i < c01; ++i) result += '1';
  cout << result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12) << fixed;
  solve(0);
  return 0;
}
