#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
vector<int> prefix_function(string s) {
  int n = (int)s.length();
  vector<int> pi(n);
  for (int i = 1; i < n; i++) {
    int 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;
}
void solve() {
  string s, t;
  cin >> s >> t;
  if (t.length() > s.length()) {
    cout << s << "\n";
    return;
  }
  long long int zs = 0, os = 0;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == '1') {
      os++;
    } else {
      zs++;
    }
  }
  long long int zt = 0, ot = 0;
  for (long long int i = 0; i < t.length(); i++) {
    if (t[i] == '1') {
      ot++;
    } else {
      zt++;
    }
  }
  vector<int> v = prefix_function(t);
  long long int len = v[(long long int)(v.size()) - 1];
  if (zt > zs || ot > os) {
    cout << s << endl;
    return;
  }
  long long int one = 0, zero = 0;
  for (long long int i = len; i < t.length(); i++) {
    if (t[i] == '1') {
      one++;
    } else {
      zero++;
    }
  }
  string add = t.substr(len, t.length() - len);
  string ans = t;
  zs -= zt;
  os -= ot;
  while (1) {
    if (zs >= zero && os >= one) {
      ans += add;
      zs -= zero;
      os -= one;
    } else {
      break;
    }
  }
  while (zs != 0) {
    ans += '0';
    zs--;
  }
  while (os != 0) {
    ans += '1';
    os--;
  }
  cout << ans << "\n";
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
