#include <bits/stdc++.h>
using namespace std;
int p[500050], freq[2];
void prefix_function(string s) {
  p[0] = 0;
  for (int i = 1; i < s.size(); i++) {
    p[i] = p[i - 1];
    while (p[i] > 0 && s[i] != s[p[i]]) p[i] = p[p[i] - 1];
    if (s[i] == s[p[i]]) p[i]++;
  }
}
int main() {
  int i, at;
  string s, t;
  cin >> s;
  for (i = 0; i < s.size(); i++) freq[s[i] - '0']++;
  cin >> t;
  prefix_function(t);
  at = 0;
  while (1) {
    if (!freq[0] && !freq[1])
      break;
    else if (!freq[0])
      printf("1"), freq[1]--;
    else if (!freq[1])
      printf("0"), freq[0]--;
    else {
      printf("%d", t[at] - '0'), freq[t[at] - '0']--;
      at++;
      if (at == t.size()) at = p[t.size() - 1];
    }
  }
  printf("\n");
}
