#include <bits/stdc++.h>
using namespace std;
string s, t;
long long hashprefix[500007];
long long power[500007];
long long tzr = 0, ton = 0;
void generatehashvalue() {
  hashprefix[0] = t[0];
  for (long long i = 1; i < t.length(); ++i) {
    long long v = t[i];
    hashprefix[i] = (hashprefix[i - 1] * 41 + (v)) % 1000000009;
    if (t[i] == '0') tzr++;
    if (t[i] == '1') ton++;
  }
  if (t[0] == '0') tzr++;
  if (t[0] == '1') ton++;
}
void cp() {
  power[0] = 1;
  for (long long i = 1; i < t.length(); ++i)
    power[i] = (power[i - 1] * 41) % 1000000009;
}
int main() {
  cin >> s >> t;
  generatehashvalue();
  cp();
  long long pos = t.length() - 1;
  long long id = -1;
  for (long long i = 0; i < pos; ++i) {
    long long tpos = pos - i;
    long long val =
        (hashprefix[pos] -
         (hashprefix[tpos - 1] * power[pos - tpos + 1]) % 1000000009) %
        1000000009;
    if (val < 0) val += 1000000009;
    if (val == hashprefix[i]) id = i;
  }
  long long szr = 0, son = 0;
  for (long long i = 0; i < s.length(); ++i) {
    if (s[i] == '0') szr++;
    if (s[i] == '1') son++;
  }
  if (s.length() < t.length() || szr < tzr || son < ton) {
    cout << s << endl;
  } else {
    cout << t;
    szr -= tzr;
    son -= ton;
    while (1) {
      long long mark = 0;
      for (long long i = id + 1; i < t.length(); ++i) {
        if (szr == 0 || son == 0) {
          mark = 1;
          break;
        }
        cout << t[i];
        if (t[i] == '1') son--;
        if (t[i] == '0') szr--;
      }
      if (mark == 1) break;
    }
    for (long long i = 1; i <= szr; ++i) cout << 0;
    for (long long i = 1; i <= son; ++i) cout << 1;
  }
}
