#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }
char s[500010], t[500010];
int m, n, cnt0, cnt1;
int nxt[500010], ans[500010];
void Get_Next() {
  nxt[0] = -1;
  int j = 0, k = -1;
  while (j <= n) {
    if (k == -1 || t[j] == t[k])
      nxt[++j] = ++k;
    else
      k = nxt[k];
  }
}
bool fl;
int main() {
  scanf("%s", s), scanf("%s", t), m = strlen(s), n = strlen(t);
  t[n] = '$';
  for (int i = 1; i <= m; ++i)
    if (s[i - 1] == '0')
      cnt0++;
    else
      cnt1++;
  Get_Next();
  for (int i = 0; i < n; ++i) {
    if (t[i] == '0' && cnt0 == 0) {
      fl = 1;
      break;
    }
    if (t[i] == '1' && cnt1 == 0) {
      fl = 1;
      break;
    }
    ans[i] = t[i] - '0';
    if (t[i] == '0')
      cnt0--;
    else
      cnt1--;
  }
  if (fl) {
    cout << s << '\n';
    return 0;
  }
  int now = n, kk = n;
  while (1) {
    if (now == n) now = nxt[n];
    if (t[now] == '0' && cnt0 == 0) {
      for (int i = 1; i <= cnt1; ++i) ans[kk + i - 1] = 1;
      break;
    }
    if (t[now] == '1' && cnt1 == 0) {
      for (int i = 1; i <= cnt0; ++i) ans[kk + i - 1] = 0;
      break;
    }
    ans[kk++] = t[now] - '0';
    if (t[now] == '0')
      cnt0--;
    else
      cnt1--;
    now++;
    if (kk > m) break;
  }
  for (int i = 0; i < m; ++i) cout << ans[i];
  cout << '\n';
  return 0;
}
