#include <bits/stdc++.h>
using namespace std;
int nxt[500005];
int main() {
  string s, t;
  cin >> s >> t;
  int n = t.size();
  nxt[0] = -1;
  for (int i = 1; i < n; i++) {
    int j = nxt[i - 1] + 1;
    while (t[i] != t[j] && j) j = nxt[j - 1] + 1;
    if (t[i] == t[j])
      nxt[i] = j;
    else
      nxt[i] = -1;
  }
  int cnt0 = 0, cnt1 = 0;
  for (int i = nxt[n - 1] + 1; i < n; i++)
    if (t[i] == '0')
      cnt0++;
    else
      cnt1++;
  int a = 0, b = 0;
  for (int i = 0; i < n; i++)
    if (t[i] == '0')
      a++;
    else
      b++;
  int m = s.size();
  int mxa = 0, mxb = 0;
  for (int i = 0; i < m; i++)
    if (s[i] == '0')
      mxa++;
    else
      mxb++;
  if (min(mxa - a, mxb - b) < 0) {
    cout << s << endl;
    return 0;
  }
  int x = (cnt0 == 0 ? 1e9 + 7 : (mxa - a) / cnt0);
  int y = (cnt1 == 0 ? 1e9 + 7 : (mxb - b) / cnt1);
  int k = min(x, y) + 1;
  string ans;
  for (int i = 1; i <= k; i++) {
    if (i == 1)
      ans = t;
    else {
      for (int j = nxt[n - 1] + 1; j < n; j++) ans.push_back(t[j]);
    }
  }
  a = mxa - a - (k - 1) * cnt0;
  b = mxb - b - (k - 1) * cnt1;
  while (a) {
    ans.push_back('0');
    a--;
  }
  while (b) {
    ans.push_back('1');
    b--;
  }
  cout << ans << endl;
}
