#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
string a, b;
map<char, int> d;
long long hashb[maxn], hasht[maxn], power[maxn];
int z[maxn], base, coso;
void readinp() {
  getline(cin, a);
  getline(cin, b);
}
void printa() { cout << a << endl; }
void init() {
  base = 1e9 + 7;
  coso = 29;
  power[0] = 1;
  for (int i = 1; i <= b.size(); i++) {
    hashb[i] = (hashb[i - 1] * coso + b[i - 1]) % base;
    power[i] = (power[i - 1] * coso) % base;
  }
}
long long gethasht(int i, int j) {
  return ((hasht[j] - (hasht[i - 1] * power[j - i + 1]) % base + base) % base);
}
void process() {
  init();
  for (int i = 0; i < a.size(); i++) {
    d[a[i]]++;
  }
  string t;
  t.clear();
  for (int i = 0; i < b.size(); i++) {
    if (d[b[i]] > 0) {
      t.push_back(b[i]);
      d[b[i]]--;
      hasht[i + 1] = (hasht[i] * coso + b[i]) % base;
    } else {
      printa();
      return;
    }
  }
  int countn = a.size() - b.size();
  int i = 1;
  int j = b.size() - 1;
  while (countn > 0) {
    countn--;
    int id = 0;
    while (i <= j) {
      if (j - i + 1 == b.size()) i++;
      if (gethasht(i + 1, j + 1) == hashb[j - i + 1]) {
        id = j - i + 1;
        break;
      }
      i++;
    }
    if (d[b[id]] > 0) {
      t.push_back(b[id]);
      j++;
      hasht[j + 1] = (hasht[j] * coso + t[j]) % base;
      d[b[id]]--;
    } else {
      break;
    }
  }
  cout << t;
  while (d['0']--) {
    cout << '0';
  }
  while (d['1']--) cout << '1';
}
int main() {
  readinp();
  if (a.size() < b.size())
    printa();
  else
    process();
}
