#include <bits/stdc++.h>
using namespace std;
char s[500000 + 5], t[500000 + 5];
int mnext[500000 + 5];
void getnext(char *a, int n) {
  for (int i = 2, j = 0; i <= n; i++) {
    while (j > 0 && a[i] != a[j + 1]) {
      j = mnext[j];
    }
    if (a[i] == a[j + 1]) j++;
    mnext[i] = j;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> s + 1 >> t + 1;
  int cnt1 = 0, cnt0 = 0;
  int lens = strlen(s + 1), lent = strlen(t + 1);
  for (int i = 1; i <= lens; i++) {
    if (s[i] == '1') cnt1++;
    if (s[i] == '0') cnt0++;
  }
  getnext(t, lent);
  for (int i = 1; i <= mnext[lent]; i++) {
    if (!cnt0 && !cnt1) break;
    if (t[i] == '0') {
      if (cnt0) {
        cout << '0';
        cnt0--;
      } else {
        cout << '1';
        cnt1--;
      }
    }
    if (t[i] == '1') {
      if (cnt1) {
        cout << '1';
        cnt1--;
      } else {
        cout << '0';
        cnt0--;
      }
    }
  }
  while (cnt0 || cnt1) {
    for (int i = mnext[lent] + 1; i <= lent; i++) {
      if (!cnt0 && !cnt1) break;
      if (t[i] == '0') {
        if (cnt0) {
          cout << '0';
          cnt0--;
        } else {
          cout << '1';
          cnt1--;
        }
      }
      if (t[i] == '1') {
        if (cnt1) {
          cout << '1';
          cnt1--;
        } else {
          cout << '0';
          cnt0--;
        }
      }
    }
  }
  return 0;
}
