#include <bits/stdc++.h>
using namespace std;
namespace FI {
const int SIZE = 1 << 18 | 1;
char buf[SIZE], *front, *back;
void Char(char &c) {
  if (front == back) back = (front = buf) + fread(buf, 1, SIZE, stdin);
  c = (front == back) ? (char)EOF : *front++;
}
template <typename T>
void Num(T &x) {
  char c;
  int f = 1;
  for (Char(c); c > '9' || c < '0'; Char(c))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9'; Char(c)) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
}  // namespace FI
const int maxn = 500000 + 47;
int lens, lent, fail[maxn], sum;
char s[maxn], t[maxn];
int main() {
  scanf("%s%s", s + 1, t + 1);
  lens = strlen(s + 1), lent = strlen(t + 1);
  if (lent > lens) return printf("%s\n", s + 1), 0;
  for (int i = (1); i <= (lens); i++) sum += (s[i] == '1');
  fail[1] = 0;
  for (int i = (2); i <= (lens); i++) {
    int j = fail[i - 1];
    while (j && t[j + 1] != t[i]) j = fail[j];
    fail[i] = (t[j + 1] == t[i]) ? j + 1 : j;
  }
  int nows = 0, sumt = 0;
  for (int i = (1); i <= (fail[lent]); i++) {
    if (!sum || lens - nows == sum) break;
    printf("%c", t[i]);
    nows++;
    sum -= (t[i] == '1');
  }
  for (int i = (fail[lent] + 1); i <= (lent); i++) {
    sumt += (t[i] == '1');
  }
  int len = lent - fail[lent];
  while (sum && nows + len <= lens) {
    if (sum < sumt) break;
    if (lens - nows - len < sum - sumt) break;
    nows += len;
    printf("%s", t + fail[lent] + 1);
    sum -= sumt;
  }
  for (int i = (1); i <= (sum); i++) printf("1");
  nows += sum;
  for (int i = (nows + 1); i <= (lens); i++) printf("0");
  puts("");
}
