#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
string s, t;
int n, m, a[2], b[2], suf[2], dp[maxn];
void solve() {
  cin >> s >> t;
  n = s.size(), m = t.size();
  for (int i = 0; i < n; ++i) {
    a[s[i] - '0']++;
  }
  for (int i = 0; i < m; ++i) {
    b[t[i] - '0']++;
  }
  dp[0] = -1;
  for (int i = 1, j = -1; i < m; ++i) {
    while (j != -1 && t[i] != t[j + 1]) {
      j = dp[j];
    }
    if (t[i] == t[j + 1]) {
      j++;
    }
    dp[i] = j;
  }
  for (int i = dp[m - 1] + 1; i < m; ++i) {
    suf[t[i] - '0']++;
  }
  if (a[0] >= b[0] && a[1] >= b[1]) {
    cout << t;
    a[0] -= b[0], a[1] -= b[1];
    while (a[0] >= suf[0] && a[1] >= suf[1]) {
      for (int i = dp[m - 1] + 1; i < m; ++i) {
        cout << t[i];
      }
      for (int i = 0; i < 2; ++i) {
        a[i] -= suf[i];
      }
    }
  }
  for (int i = 0; i < a[0]; ++i) {
    cout << 0;
  }
  for (int i = 0; i < a[1]; ++i) {
    cout << 1;
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
