#include <bits/stdc++.h>
using namespace std;
long long frev(long long x, long long y) { return x > y; }
long long findset(long long a, long long ds[], long long rank[]) {
  if (a == ds[a]) return a;
  ds[a] = findset(ds[a], ds, rank);
  return ds[a];
}
long long dsu(long long a, long long b, long long ds[], long long rank[]) {
  long long repa = findset(a, ds, rank);
  long long repb = findset(b, ds, rank);
  if (rank[repa] == rank[repb]) {
    rank[repb]++;
    ds[repa] = repb;
  }
  if (rank[repa] > rank[repb]) {
    ds[repb] = repa;
  } else {
    ds[repa] = repb;
  }
  return 1;
}
long long gcd(long long a, long long b) {
  if (a > b) {
    long long t = a;
    a = b;
    b = t;
  }
  if (b % a == 0)
    return a;
  else
    return gcd(a, b % a);
}
int dfs(long long r, vector<long long> g[], long long vis[], long long siz[]) {
  vis[r] = 1;
  siz[r] = 1;
  for (auto l : g[r]) {
    if (!vis[l]) {
      siz[r] += dfs(l, g, vis, siz);
    }
  }
  return siz[r];
}
int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  long long fr[2] = {0};
  for (long long i = 0; i <= s.length() - 1; i++) {
    if (s[i] == '1')
      fr[1]++;
    else
      fr[0]++;
  }
  long long m = t.length();
  long long lps[m];
  lps[0] = 0;
  long long i = 1;
  long long len = 0;
  while (i < m) {
    if (t[i] == t[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
  long long k;
  k = lps[m - 1];
  k = m - k - 1;
  string newt = "";
  for (long long i = 0; i <= k; i++) newt += t[i];
  string ans = "";
  long long h = 0;
  for (long long i = 0; i <= s.length() - 1; i++) {
    if (newt[h] == '1') {
      if (fr[1] == 0) break;
      ans += "1";
      fr[1]--;
    } else {
      if (fr[0] == 0) break;
      ans += "0";
      fr[0]--;
    }
    h++;
    if (h == newt.length()) h = 0;
  }
  for (long long j = 0; j <= fr[0] - 1; j++) ans += "0";
  for (long long j = 0; j <= fr[1] - 1; j++) ans += "1";
  cout << ans;
  cout << endl;
}
