#include <bits/stdc++.h>
using namespace std;
int nxt[500005];
string second, t;
void kmp(int n) {
  nxt[0] = nxt[1] = 0;
  for (int i = 1, j = 0; i < n; i++) {
    while (j && t[j] != t[i]) j = nxt[j];
    if (t[j] == t[i]) j++;
    nxt[i + 1] = j;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> second >> t;
  int c0 = 0, c1 = 0;
  for (int i = 0; i < second.size(); i++) {
    if (second[i] == '0')
      c0++;
    else
      c1++;
  }
  int k0 = 0, k1 = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '0')
      k0++;
    else
      k1++;
  }
  if (c0 < k0 || c1 < k1) {
    cout << second << endl;
    return 0;
  }
  kmp(t.size());
  int pre = 0;
  for (int i = 0; i < t.size(); i++) {
    second[i] = t[i];
    pre = i + 1;
  }
  c0 -= k0;
  c1 -= k1;
  for (int i = 0; i < nxt[t.size()]; i++) {
    if (t[i] == '0')
      k0--;
    else
      k1--;
  }
  while (c0 >= k0 && c1 >= k1) {
    for (int i = nxt[t.size()]; i < t.size(); i++) {
      second[pre++] = t[i];
    }
    c0 -= k0;
    c1 -= k1;
  }
  while (c0) second[pre++] = '0', c0--;
  while (c1) second[pre++] = '1', c1--;
  cout << second;
  return 0;
}
