#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 5e5 + 5;
int fail[N], cnt[5];
string s, t, ans;
void build(string &s) {
  int i = 1, len = 0;
  while (i < s.size()) {
    if (s[i] == s[len])
      fail[i] = len + 1, i++, len++;
    else
      (len > 0) ? len = fail[len - 1] : i++;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> t;
  build(t);
  for (auto i : s) cnt[i - '0']++;
  int len = t.size() - fail[t.size() - 1];
  int i = 0;
  while (i < len) {
    if (cnt[t[i] - '0']) {
      ans.push_back(t[i]), cnt[t[i] - '0']--, i++;
      if (i == len) i = 0;
    } else
      break;
  }
  for (i = len; i < t.size(); i++) {
    if (cnt[t[i] - '0']) ans.push_back(t[i]), cnt[t[i] - '0']--;
  }
  while (cnt[0]--) ans.push_back('0');
  while (cnt[1]--) ans.push_back('1');
  cout << ans << endl;
  return 0;
}
