#include <bits/stdc++.h>
using namespace std;
vector<int> Z(const string& s) {
  vector<int> z(s.length());
  z[0] = s.length();
  int L = 0;
  int R = 0;
  for (int i = 1; i < s.length(); i++) {
    if (i < R && z[i - L] < R - i) {
      z[i] = z[i - L];
    } else {
      L = i;
      R = max(R, i);
      while (R < s.length() && s[R] == s[R - L]) R++;
      z[i] = R - i;
    }
  }
  return z;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int n = t.length();
  int zeros = count(s.begin(), s.end(), '0');
  int ones = count(s.begin(), s.end(), '1');
  auto z = Z(t);
  z[0] = 0;
  int d = n;
  for (int i = 0; i < n; i++) {
    if (z[i] == n - i) {
      d = i;
      break;
    }
  }
  string res;
  for (int i = 0; i < n; i++) {
    if (t[i] == '0') {
      if (zeros <= 0) {
        cout << s << endl;
        return 0;
      }
      res.push_back('0');
      zeros--;
    } else {
      if (ones <= 0) {
        cout << s << endl;
        return 0;
      }
      res.push_back('1');
      ones--;
    }
  }
  int k = 0;
  for (int i = n; i < s.length(); i++) {
    if (zeros <= 0 || ones <= 0) break;
    res.push_back(t[n - d + k]);
    if (t[n - d + k] == '0')
      zeros--;
    else
      ones--;
    k = (k + 1) % d;
  }
  while (zeros--) res.push_back('0');
  while (ones--) res.push_back('1');
  cout << res << endl;
  return 0;
}
