#include <bits/stdc++.h>
using namespace std;
const int sz = 500500;
int n, m;
string s, t;
int us = 0, ut = 0, zs = 0, zt = 0;
const long long mod = 1e9 + 7;
long long p = 3;
long long h[sz];
long long ppow[sz];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  us = ut = zs = zt = 0;
  cin >> s >> t;
  n = s.length();
  m = t.length();
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      us++;
    } else {
      zs++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (t[i] == '1') {
      ut++;
    } else {
      zt++;
    }
  }
  for (int i = 0; i < m; i++) {
    h[i] = t[i] - '0' + 1;
    if (i) {
      h[i] += (h[i - 1] * p) % mod;
      h[i] %= mod;
    }
  }
  int from = m;
  ppow[0] = 1;
  for (int i = 1; i < m; i++) {
    ppow[i] = (ppow[i - 1] * p) % mod;
  }
  for (int i = 1; i < m; i++) {
    long long cur = (mod + h[m - 1] - (h[i - 1] * ppow[m - i]) % mod) % mod;
    if (cur == h[m - i - 1]) {
      from = i;
      break;
    }
  }
  int ansU = 0, ansZ = 0;
  for (int i = 0; i < from; i++) {
    if (t[i] == '1')
      ansU++;
    else
      ansZ++;
  }
  int total = 0;
  if (ansU != 0) {
    total = us / ansU;
  }
  if (ansZ != 0) {
    total = zs / ansZ;
  }
  if (ansU != 0 && ansZ != 0) {
    total = min(us / ansU, zs / ansZ);
  }
  string cur = t.substr(0, from);
  for (int i = 0; i < n; i++) {
    if (cur[i % from] == '0') {
      if (zs) {
        printf("0");
        zs--;
      } else {
        printf("1");
        us--;
      }
    } else {
      if (us) {
        printf("1");
        us--;
      } else {
        printf("0");
        zs--;
      }
    }
  }
  return 0;
}
