#include <bits/stdc++.h>
using namespace std;
int z_func(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;
  }
  for (int i = 0; i < s.length(); ++i)
    if (z[i] + i == s.length()) return i;
  return s.length();
}
void solve() {
  string s, t;
  cin >> s >> t;
  int c[2] = {0, 0};
  int pos = z_func(t);
  for (int i = 0; i < s.length(); ++i)
    if (s[i] == '0')
      c[0]++;
    else
      c[1]++;
  string templ = t;
  string add = t.substr(t.length() - pos);
  while (templ.length() < s.length()) templ += add;
  string res;
  for (int i = 0; i < s.length(); ++i) {
    int symb = templ[i] - '0';
    if (c[symb] == 0) symb ^= 1;
    res += (symb + '0');
    c[symb]--;
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
