#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;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int freq[2] = {0};
  for (char c : s) {
    freq[c - '0']++;
  }
  if (s.size() < t.size()) {
    cout << s << '\n';
    return 0;
  }
  string ans = "";
  for (char c : t) {
    if (freq[c - '0'] <= 0) {
      cout << s << '\n';
      return 0;
    }
    ans += c;
    freq[c - '0']--;
  }
  vector<int> z = z_function(t);
  int n = t.size();
  string to_add = t;
  for (int i = 1; i < n; i++) {
    if (z[i] == n - i) {
      to_add = t.substr(n - i);
      break;
    }
  }
  bool done = true;
  while (done) {
    for (char c : to_add) {
      if (freq[c - '0'] > 0) {
        ans += c;
        freq[c - '0']--;
      } else {
        done = false;
        break;
      }
    }
  }
  for (int i = 0; i < 2; i++) {
    while (freq[i] > 0) {
      freq[i]--;
      ans += ('0' + i);
    }
  }
  cout << ans << '\n';
  return 0;
}
