#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 10;
const long long MOD = 1e9 + 7;
int N, M, K, Q;
int cnts[3], cntt[3];
int lps[MAX];
string s, t;
void construct_lps() {
  int j = 0;
  lps[0] = 0;
  for (int i = 1; i < t.size(); ++i) {
    if (t[j] == t[i]) {
      j++;
      lps[i] = j;
    } else {
      if (j == 0) {
        lps[i] = 0;
      } else {
        j = lps[j - 1];
        i--;
      }
    }
  }
}
int main() {
  int i, j;
  cin >> s >> t;
  for (i = 0; i < s.size(); ++i) cnts[s[i] - '0']++;
  for (i = 0; i < t.size(); ++i) cntt[t[i] - '0']++;
  N = t.size();
  construct_lps();
  int pre = 0x3f3f3f3f;
  for (i = N - 1; i >= 0; --i) {
    if (lps[i] == 0) break;
    if (lps[i] >= pre) break;
    pre = lps[i];
  }
  string sub = t.substr(N - 1 - i);
  int a = 0;
  int b = 0;
  for (j = 0; j < sub.size(); ++j) {
    if (t[j] == '0')
      a++;
    else
      b++;
  }
  if (cnts[0] >= cntt[0] && cnts[1] >= cntt[1]) {
    cout << t;
    cnts[0] -= cntt[0];
    cnts[1] -= cntt[1];
  }
  while (cnts[0] >= a && cnts[1] >= b) {
    cout << sub;
    cnts[0] -= a;
    cnts[1] -= b;
  }
  while (cnts[0]--) printf("0");
  while (cnts[1]--) printf("1");
}
