#include <bits/stdc++.h>
using namespace std;
vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int MAX = 1e5 + 55;
const int inf = 1e9 + 77;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-7;
string P;
int b[500010], n, m;
void kmpPreprocess() {
  int i = 0, j = -1;
  b[0] = -1;
  while (i < m) {
    while (j >= 0 && P[i] != P[j]) j = b[j];
    i++;
    j++;
    b[i] = j;
  }
}
int cnt[2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s >> P;
  n = s.size();
  m = P.size();
  kmpPreprocess();
  for (int i = 0; i < n; ++i) {
    cnt[s[i] - '0']++;
  }
  int j = 0;
  for (int i = 0; i < n; ++i, ++j) {
    if (j == m) j = b[m];
    int cur = P[j] - '0';
    if (!cnt[cur]) break;
    cout << cur;
    --cnt[cur];
  }
  while (cnt[1]--) cout << 1;
  while (cnt[0]--) cout << 0;
  return 0;
}
