#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int no = 0;
  for (int i = 0; i < (int)(n); i++) no += s[i] - '0';
  int nz = n - no;
  int m = t.size();
  int p = 3;
  long long mod = 1e9 + 7;
  vector<long long> ppows(m + 1);
  ppows[0] = 1;
  for (int j = (int)(1); j < (int)(m + 1); j++) {
    ppows[j] = (p * ppows[j - 1]) % mod;
  }
  vector<long long> hash(m + 1, 0);
  hash[0] = 0;
  for (int j = (int)(1); j < (int)(m + 1); j++) {
    hash[j] = (p * hash[j - 1] + t[j - 1] - '0' + 1) % mod;
  }
  int minpfx = -1;
  for (int j = (int)(1); j < (int)(m + 1); j++) {
    long long a = hash[m - j];
    long long b =
        ((((hash[m] - hash[j] * ppows[m - j]) % (mod)) + (mod)) % (mod));
    if (a == b) {
      minpfx = j;
      break;
    }
  }
  assert(minpfx > -1);
  string ans;
  for (int i = 0; i < (int)(n); i++) {
    if (nz == 0) {
      ans.push_back('1');
      no--;
    } else if (no == 0) {
      ans.push_back('0');
      nz--;
    } else if (t[i % minpfx] == '0') {
      ans.push_back('0');
      nz--;
    } else {
      ans.push_back('1');
      no--;
    }
  }
  cout << ans << endl;
  return 0;
}
