#include <bits/stdc++.h>
using namespace std;
namespace Base {
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template <typename T>
void read(T &x) {
  x = 0;
  int fh = 1;
  double num = 1.0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  if (ch == '.') {
    ch = getchar();
    while (isdigit(ch)) {
      num /= 10;
      x = x + num * (ch - '0');
      ch = getchar();
    }
  }
  x = x * fh;
}
template <typename T>
void chmax(T &x, T y) {
  x = x < y ? y : x;
}
template <typename T>
void chmin(T &x, T y) {
  x = x > y ? y : x;
}
}  // namespace Base
using namespace Base;
const int N = 500010;
char s[N], t[N];
int ls, lt, ned[2], cnt[2], bak[2], nxt[N], num;
void kmp(char *s, int len, int *nxt) {
  nxt[1] = 0;
  for (int i = 2; i <= len; i++) {
    int p = i - 1;
    while (p != 0) {
      if (s[nxt[p] + 1] != s[i])
        p = nxt[p];
      else {
        nxt[i] = nxt[p] + 1;
        break;
      }
    }
  }
}
int main() {
  scanf("\n%s\n%s", s + 1, t + 1);
  int ls = strlen(s + 1), lt = strlen(t + 1);
  for (int i = 1; i <= ls; i++) cnt[s[i] - '0']++;
  for (int i = 1; i <= lt; i++) ned[t[i] - '0']++;
  kmp(t, lt, nxt);
  for (int i = nxt[lt] + 1; i <= lt; i++) bak[t[i] - '0']++;
  if (cnt[0] < ned[0] || cnt[1] < ned[1]) {
    for (int i = 1; i <= cnt[0]; i++) printf("0");
    for (int i = 1; i <= cnt[1]; i++) printf("1");
    return 0;
  }
  cnt[0] -= ned[0], cnt[1] -= ned[1];
  if (bak[0] == 0)
    num = cnt[1] / bak[1];
  else if (bak[1] == 0)
    num = cnt[0] / bak[0];
  else
    num = min(cnt[0] / bak[0], cnt[1] / bak[1]);
  cnt[0] -= bak[0] * num;
  cnt[1] -= bak[1] * num;
  for (int i = 1; i <= lt; i++) printf("%c", t[i]);
  for (int i = 1; i <= num; i++)
    for (int j = nxt[lt] + 1; j <= lt; j++) printf("%c", t[j]);
  for (int i = 1; i <= cnt[0]; i++) printf("0");
  for (int i = 1; i <= cnt[1]; i++) printf("1");
  printf("\n");
  return 0;
}
