#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t;
  long long int on = 0, ze = 0, onn = 0, zee = 0, ans = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1')
      on++;
    else
      ze++;
  }
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '1')
      onn++;
    else
      zee++;
  }
  if ((onn + zee) <= (on + ze) && onn <= on && zee <= ze) {
    on -= onn;
    ze -= zee;
    ans++;
  }
  int i, j, k, f, b = 0, n = t.size();
  int L = 0, R = 0;
  int z[n];
  for (int i = 1; i < t.size(); i++) {
    if (i > R) {
      L = R = i;
      while (R < n && t[R - L] == t[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && t[R - L] == t[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (z[i] + i == t.size()) {
      k = i;
      b = 1;
      break;
    }
  }
  if (b == 1) {
    for (int i = 0; i < ans; i++) cout << t;
    int u = z[k];
    u = u % n;
    while (on != 0 || ze != 0) {
      if (ze > 0 && t[u] == '0') {
        cout << '0';
        ze--;
      } else if (on > 0 && t[u] == '1') {
        cout << '1';
        on--;
      } else {
        if (ze > 0) {
          cout << '0';
          ze--;
        } else {
          cout << '1';
          on--;
        }
      }
      u++;
      if (u == t.size()) u = z[k];
    }
  } else {
    while ((onn + zee) <= (on + ze) && onn <= on && zee <= ze) {
      on -= onn;
      ze -= zee;
      ans++;
    }
    for (int i = 0; i < ans; i++) cout << t;
    for (int i = 0; i < on; i++) cout << '1';
    for (int i = 0; i < ze; i++) cout << '0';
  }
  return 0;
}
