#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
string s, t;
int pref[N], n, m, s1 = 0, s0 = 0, t1 = 0, t0 = 0;
void read() {
  cin >> s >> t;
  n = s.length(), m = t.length();
}
void build() {
  int j = 0, i = 1;
  pref[0] = 0;
  while (i < m) {
    if (t[i] == t[j])
      pref[i] = j + 1, i++, j++;
    else {
      if (j == 0)
        pref[i] = 0, i++;
      else
        j = pref[j - 1];
    }
  }
}
void solve() {
  for (auto ch : s)
    if (ch == '1') s1++;
  for (auto ch : t)
    if (ch == '1') t1++;
  s0 = n - s1;
  t0 = m - t1;
  int lps = pref[m - 1];
  int lps1 = 0, lps0 = 0;
  for (int i = 0; i < lps; i++)
    if (t[i] == '1') lps1++;
  lps0 = lps - lps1;
  bool first = true;
  string ok = t.substr(lps);
  while (true) {
    if (s0 >= t0 && s1 >= t1) {
      if (first)
        cout << t;
      else {
        cout << ok;
      }
      s0 -= t0, s1 -= t1;
    } else
      break;
    if (first) {
      t0 = t0 - lps0;
      t1 = t1 - lps1;
      first = false;
    }
  }
  while (s0--) cout << '0';
  while (s1--) cout << '1';
}
int main() {
  read();
  build();
  solve();
  return 0;
}
