#include <bits/stdc++.h>
using namespace std;
vector<long long> prefix_function(string s) {
  long long n = (long long)s.length();
  vector<long long> pi(n);
  for (long long i = 1; i < n; i++) {
    long long j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) j++;
    pi[i] = j;
  }
  return pi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  if (t.length() > s.length()) {
    cout << s << '\n';
    return 0;
  }
  string t2 = t;
  t2.erase(t2.begin());
  long long a0, a1;
  a0 = a1 = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == '1')
      a1++;
    else
      a0++;
  }
  long long k = 0, c = 0;
  bool chk = true;
  string fin = t + "-" + t2;
  vector<long long> arr = prefix_function(fin);
  long long p = 0;
  p = arr[arr.size() - 1];
  string ss;
  for (long long i = p; i < t.length(); i++) {
    ss.push_back(t[i]);
  }
  for (long long i = 0; i < s.length(); i++) {
    if (chk && c == t.length()) {
      if (ss[k] == '1') {
        if (a1 >= 1) {
          a1--;
          cout << 1;
        } else {
          a0--;
          cout << 0;
        }
      } else {
        if (a0 >= 1) {
          a0--;
          cout << 0;
        } else {
          a1--;
          cout << 1;
        }
      }
      k++;
      k = k % (ss.length());
    } else {
      if (t[k] == '1') {
        if (a1 >= 1) {
          a1--;
          cout << 1;
          c++;
        } else {
          a0--;
          cout << 0;
          chk = false;
        }
      } else {
        if (a0 >= 1) {
          a0--;
          cout << 0;
          c++;
        } else {
          a1--;
          cout << 1;
          chk = false;
        }
      }
      k++;
      k = k % (t.length());
    }
  }
  return 0;
}
