#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 60;
int c[20], fail[N], d[20], e[20], n;
char s[N], t[N];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  n = strlen(t + 1);
  for (int i = 1; s[i]; i++) c[s[i] - '0']++;
  fail[1] = 0;
  for (int i = 2; i <= n; i++) {
    int p = fail[i - 1];
    while (p && t[p + 1] != t[i]) p = fail[p];
    if (t[p + 1] == t[i])
      fail[i] = p + 1;
    else
      fail[i] = 0;
  }
  int bor = fail[n];
  for (int i = 1; i <= n; i++) {
    if (i <= bor)
      d[t[i] - '0']++;
    else
      e[t[i] - '0']++;
  }
  if (d[0] + e[0] <= c[0] && d[1] + e[1] <= c[1]) {
    for (int i = 1; i <= bor; i++) putchar(t[i]);
    c[0] -= d[0];
    c[1] -= d[1];
    while (e[0] <= c[0] && e[1] <= c[1]) {
      for (int i = bor + 1; i <= n; i++) putchar(t[i]);
      c[0] -= e[0];
      c[1] -= e[1];
    }
    for (int i = 1; i <= c[0]; i++) putchar('0');
    for (int i = 1; i <= c[1]; i++) putchar('1');
    puts("");
  } else {
    for (int i = 1; s[i]; i++) putchar(s[i]);
    puts("");
  }
  return 0;
}
