#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
int prefix_funtion(string s, int n) {
  vector<int> pi(n);
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) j++;
    pi[i] = j;
  }
  return pi[n - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b;
  cin >> a >> b;
  long long int a0 = 0, a1 = 0, b0 = 0, b1 = 0;
  for (long long int i = 0; i < a.length(); i++) {
    a0 += (a[i] == '0');
    a1 += (a[i] == '1');
  }
  for (long long int i = 0; i < b.length(); i++) {
    b0 += (b[i] == '0');
    b1 += (b[i] == '1');
  }
  long long int ind = prefix_funtion(b, b.length());
  string expected;
  long long int i;
  for (i = 0; i < b.length() && i < a.length(); i++) expected.push_back(b[i]);
  long long int len = b.length() - ind;
  for (; i < a.length(); i++) {
    long long int x = i - b.length();
    x = x % len;
    expected.push_back(b[x + ind]);
  }
  for (long long int i = 0; i < expected.length(); i++) {
    if (expected[i] == '0') {
      if (a0) {
        cout << 0;
        a0--;
      } else
        break;
    } else {
      if (a1) {
        cout << 1;
        a1--;
      } else
        break;
    }
  }
  for (long long int i = 0; i < a0; i++) cout << 0;
  for (long long int i = 0; i < a1; i++) cout << 1;
  cout << endl;
}
