#include <bits/stdc++.h>
using namespace std;
vector<int> zalgorithm(string s) {
  int len = (int)s.length();
  vector<int> res(len, 0);
  int c = 0;
  for (int i = 1; i < len; i++) {
    if (i + res[i - c] < c + res[c]) {
      res[i] = res[i - c];
    } else {
      int j = max(0, c + res[c] - i);
      while (i + j < len && s[j] == s[i + j]) j++;
      res[i] = j;
      c = i;
    }
  }
  res[0] = len;
  return res;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int cnt[2] = {};
  int ok[2] = {};
  for (char c : s) cnt[c - '0']++;
  for (int i = 0; i < 2; i++) ok[i] = cnt[i];
  for (char c : t) ok[c - '0']--;
  for (int i = 0; i < 2; i++) {
    if (ok[i] < 0) {
      cout << s << endl;
      return 0;
    }
  }
  auto z = zalgorithm(t);
  string head = t;
  for (int i = 1; i < (int)t.length(); i++) {
    if (z[i] == (int)t.length() - i) {
      head = t.substr(0, i);
      break;
    }
  }
  int need[2] = {};
  int cycle = 1 << 30;
  for (char c : head) need[c - '0']++;
  for (int i = 0; i < 2; i++) {
    if (need[i] == 0) continue;
    cycle = min(cycle, cnt[i] / need[i]);
  }
  for (int i = 0; i < 2; i++) {
    cnt[i] -= need[i] * cycle;
  }
  string ans;
  for (int i = 0; i < cycle; i++) {
    ans += head;
  }
  for (char c : head) {
    if (cnt[c - '0']-- == 0) break;
    ans += c;
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      ans += i + '0';
    }
  }
  cout << ans << endl;
  return 0;
}
