#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
void warp() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
}
vector<long long> prefix(string s) {
  long long n = s.size();
  vector<long long> ans(n, -1);
  ans[0] = -1;
  for (long long i = 1; i < n; i++) {
    long long cur = i - 1;
    while (cur != -1)
      if (s[i] == s[ans[cur] + 1]) {
        ans[i] = ans[cur] + 1;
        break;
      } else
        cur = ans[cur];
  }
  return ans;
}
ostream& operator<<(ostream& out, vector<long long>& a) {
  for (long long i = 0; i < a.size(); i++) cout << a[i] << " ";
  return out;
}
void print(vector<long long>& cnt, long long i) {
  if (cnt[i] > 0) {
    cout << i;
    cnt[i]--;
  } else if (cnt[i ^ 1] > 0) {
    cout << (i ^ 1);
    cnt[i ^ 1]--;
  }
}
signed main() {
  warp();
  string s, t;
  cin >> s >> t;
  vector<long long> pr = prefix(t);
  long long over = pr.back() + 1;
  vector<long long> cnt(2);
  for (long long i = 0; i < s.size(); i++) cnt[s[i] - '0']++;
  for (long long i = 0; i < over; i++) print(cnt, t[i] - '0');
  while (cnt[0] + cnt[1]) {
    for (long long i = over; i < t.size(); i++) print(cnt, t[i] - '0');
  }
  while (cnt[0]) print(cnt, 0);
  while (cnt[1]) print(cnt, 1);
  cout << endl;
  return 0;
}
