#include <bits/stdc++.h>
using namespace std;
const int S = (int)1e6;
int dp[S];
string txt, pat;
vector<int> ans;
void kmp() {
  int i = 0, j = -1, n = ((int)(txt.size())), m = ((int)(pat.size()));
  dp[0] = -1;
  while (i < m) {
    while (j >= 0 and pat[i] != pat[j]) j = dp[j];
    i++, j++;
    dp[i] = j;
  }
}
int main() {
  ios::sync_with_stdio(0);
a:
  string s, s2;
  cin >> s >> s2;
  int ones = 0, zeros = 0, ones2 = 0, zeros2 = 0, ones3 = 0, zeros3 = 0;
  for (char c : s) (c == '0') ? zeros++ : ones++;
  pat = s2;
  kmp();
  string res = s2, r = s2.substr(dp[((int)(s2.size()))],
                                 ((int)(s2.size())) - dp[((int)(s2.size()))]);
  for (char c : res) (c == '0') ? zeros2++ : ones2++;
  for (char c : r) (c == '0') ? zeros3++ : ones3++;
  if (zeros2 > zeros or ones2 > ones)
    cout << s << '\n';
  else {
    while (1) {
      if (zeros2 + zeros3 > zeros or ones2 + ones3 > ones) break;
      res += r;
      zeros2 += zeros3;
      ones2 += ones3;
    }
    for (int i = 0; i < zeros - zeros2; i++) res += '0';
    for (int i = 0; i < ones - ones2; i++) res += '1';
    cout << res << '\n';
  }
}
