#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  int n = 0, m = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      n++;
    else
      m++;
  }
  int w = 0, r = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '0')
      w++;
    else
      r++;
  }
  if ((r > m) || (w > n)) {
    cout << s;
    return 0;
  }
  int w1 = n - w, r1 = m - r;
  vector<int> f(t.size());
  f[0] = 0;
  int j;
  for (int i = 1; i < t.size(); i++) {
    j = f[i - 1];
    while ((j > 0) && (t[j] != t[i])) {
      j = f[j - 1];
    }
    if (t[j] == t[i]) {
      j++;
    }
    f[i] = j;
  }
  string t1 = t;
  string q;
  int w2 = 0, r2 = 0;
  for (int i = f[t.size() - 1]; i < t.size(); i++) {
    q += t[i];
    if (t[i] == '0')
      w2++;
    else
      r2++;
  }
  while (((w1 - w2) >= 0) && (r1 - r2) >= 0) {
    t1.append(q);
    w1 -= w2;
    r1 -= r2;
  }
  for (int i = 0; i < w1; i++) {
    t1 += '0';
  }
  for (int j = 0; j < r1; j++) {
    t1 += '1';
  }
  cout << t1;
}
