#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      ++z[i];
    }
    if (i + z[i] - 1 > r) {
      l = i, r = i + z[i] - 1;
    }
  }
  return z;
}
void solve() {
  string a, b;
  cin >> a >> b;
  int ones = 0, zeros = 0;
  int A = ((int)(a).size()), B = ((int)(b).size());
  for (int i = 0; i < A; ++i) {
    if (a[i] == '0') {
      ++zeros;
    } else {
      ++ones;
    }
  }
  for (int i = 0; i < B; ++i) {
    if (b[i] == '0') {
      --zeros;
    } else {
      --ones;
    }
  }
  if (zeros < 0 || ones < 0) {
    cout << (a) << '\n';
    return;
  }
  vector<int> z = z_function(b);
  int len = 0;
  for (int i = 1; i < B; ++i) {
    if (z[i] + i == B) {
      len = z[i];
      break;
    }
  };
  string ret = string(b);
  while (1) {
    pair<int, int> memo{zeros, ones};
    for (int i = len; i < B; ++i) {
      if (b[i] == '0') {
        --zeros;
      } else {
        --ones;
      }
    }
    if (zeros < 0 || ones < 0) {
      for (int i = 0; i < memo.first; ++i) {
        ret += '0';
      }
      for (int i = 0; i < memo.second; ++i) {
        ret += '1';
      }
      break;
    }
    for (int i = len; i < B; ++i) {
      ret += b[i];
    }
  }
  cout << (ret) << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
