#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long maxn = 5e5 + 10, maxval = 1e9 + 10, mlg = (1 << 18) + 10;
long long kmp[maxn], cnt[2];
string s, t, ans;
void cal(string s) {
  for (int i = 1; i < s.length(); i++) {
    long long tmp = kmp[i - 1];
    while (tmp > 0 && s[tmp] != s[i]) {
      tmp = kmp[tmp - 1];
    }
    if (s[i] == s[tmp]) {
      tmp++;
    }
    kmp[i] = tmp;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s >> t;
  cal(t);
  for (int i = 0; i < s.length(); i++) {
    cnt[s[i] - '0']++;
  }
  long long tmp = 0;
  for (int i = 0; i < s.length(); i++) {
    if (cnt[t[tmp] - '0']) {
      ans += t[tmp];
      cnt[t[tmp] - '0']--;
      tmp++;
      if (tmp == t.length()) {
        tmp = kmp[t.length() - 1];
      }
    } else {
      break;
    }
  }
  while (cnt[0]) {
    ans += '0';
    cnt[0]--;
  }
  while (cnt[1]) {
    ans += '1';
    cnt[1]--;
  }
  cout << ans << endl;
}
