#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
string s, p;
int b[100005 * 6];
int n, m;
void kmpPreprocess() {
  int i = 0, j = -1;
  b[i] = j;
  while (i < m) {
    while (j >= 0 && p[i] != p[j]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
string r;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> p;
  n = s.size();
  m = p.size();
  kmpPreprocess();
  int cnt = b[m];
  int cp = 0, cpp = 0;
  for (int i = 0; i < (m); i++) {
    if (p[i] == '1')
      cp++;
    else
      cpp++;
    if (i < cnt) continue;
    r.push_back(p[i]);
  }
  int c0 = 0, c1 = 0;
  for (int i = 0; i < (n); i++) {
    if (s[i] == '1')
      c1++;
    else
      c0++;
  }
  if (n < m || (cp > c1 || cpp > c0)) {
    cout << s << endl;
    return 0;
  }
  c0 -= cpp;
  c1 -= cp;
  int i = 0, sz = (int)r.size();
  while (c0 || c1) {
    if (r[i] == '1') {
      if (c1) {
        c1--;
        p.push_back('1');
      } else {
        c0--;
        p.push_back('0');
      }
    } else {
      if (c0) {
        c0--;
        p.push_back('0');
      } else {
        c1--;
        p.push_back('1');
      }
    }
    i++;
    i %= sz;
  }
  cout << p << endl;
  return 0;
}
