#include <bits/stdc++.h>
using namespace std;
int get_pi(const string& s) {
  int n = s.size(), j = 0;
  vector<int> a(n);
  for (int i = 1; i < n; i++) {
    while (j && s[j] != s[i]) j = a[j - 1];
    if (s[j] == s[i]) j++;
    a[i] = j;
  }
  return a[n - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int c0 = 0, c1 = 0;
  for (char c : s) {
    if (c == '0')
      c0++;
    else
      c1++;
  }
  auto put0 = [&]() {
    if (c0) {
      cout << '0';
      c0--;
    }
  };
  auto put1 = [&]() {
    if (c1) {
      cout << '1';
      c1--;
    }
  };
  int pi = get_pi(t);
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '0') {
      if (c0)
        put0();
      else
        put1();
    } else {
      if (c1)
        put1();
      else
        put0();
    }
    if (c0 == 0 && c1 == 0) break;
  }
  while (c0 > 0 || c1 > 0) {
    for (int i = pi; i < t.size(); i++) {
      if (t[i] == '0') {
        if (c0)
          put0();
        else
          put1();
      } else {
        if (c1)
          put1();
        else
          put0();
      }
      if (c0 == 0 && c1 == 0) break;
    }
  }
  cout << '\n';
  return 0;
}
