#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, inf = 1000000;
int n, m, Next[N];
string s1, s2;
int main() {
  ios::sync_with_stdio(false);
  cin >> s1;
  int l1 = s1.length();
  cin >> s2;
  int l2 = s2.length();
  Next[0] = -1;
  int k = -1, j = 0;
  while (j < l2) {
    while (k > 0 && s2[j] != s2[k]) k = Next[k - 1] + 1;
    if (s2[j] == s2[k])
      Next[j] = k;
    else
      Next[j] = k = -1;
    j++;
    k++;
  }
  int a = 0, b = 0, c = 0;
  for (int i = 0; i <= l1 - 1; i++) a += (s1[i] == '1');
  for (int i = 0; i <= l2 - 1; i++) b += (s2[i] == '1');
  for (int i = Next[l2 - 1] + 1; i <= l2 - 1; i++) c += (s2[i] == '1');
  if (b > a || l2 - b > l1 - a) {
    cout << s1 << endl;
    return 0;
  }
  int t = min(c > 0 ? (a - b) / c : inf,
              c < l2 - Next[l2 - 1] - 1
                  ? (l1 - a - l2 + b) / (l2 - Next[l2 - 1] - 1 - c)
                  : inf);
  cout << s2;
  for (int i = 1; i <= t; i++)
    for (int j = Next[l2 - 1] + 1; j <= l2 - 1; j++) cout << s2[j];
  for (int i = 1; i <= a - b - c * t; i++) cout << '1';
  for (int i = 1; i <= l1 - a - l2 + b - t * (l2 - Next[l2 - 1] - 1 - c); i++)
    cout << '0';
  cout << endl;
}
