#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 10;
const int MOD = (int)1e9 + 7;
int longestPrefixSuffix(string s);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int cnt0s = 0, cnt1s = 0, cnt0t = 0, cnt1t = 0;
  for (int i = 0; i < s.size(); i++) cnt0s += s[i] == '0', cnt1s += s[i] == '1';
  for (int i = 0; i < t.size(); i++) cnt0t += t[i] == '0', cnt1t += t[i] == '1';
  if (cnt0s < cnt0t || cnt1s < cnt1t) return cout << s, 0;
  cout << t;
  cnt0s -= cnt0t, cnt1s -= cnt1t;
  t = t.substr(longestPrefixSuffix(t));
  cnt0t = 0, cnt1t = 0;
  for (int i = 0; i < t.size(); i++) cnt0t += t[i] == '0', cnt1t += t[i] == '1';
  while (cnt0s >= cnt0t && cnt1s >= cnt1t)
    cout << t, cnt0s -= cnt0t, cnt1s -= cnt1t;
  if (cnt0s) cout << string(cnt0s, '0');
  if (cnt1s) cout << string(cnt1s, '1');
  return 0;
}
int longestPrefixSuffix(string s) {
  int n = s.length();
  int lps[n];
  lps[0] = 0;
  int len = 0;
  int i = 1;
  while (i < n) {
    if (s[i] == s[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0)
        len = lps[len - 1];
      else {
        lps[i] = 0;
        i++;
      }
    }
  }
  return lps[n - 1];
}
