#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << x; }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
  return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  for (auto &i : t) os << i << " ";
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
  for (pair<T1, T2> &t : v) is >> t.first >> t.second;
  return is;
}
const long long mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, t;
  cin >> s >> t;
  long long n = t.size(), m = s.size();
  vector<long long> cnt(2, 0);
  for (auto x : s) cnt[x - '0']++;
  vector<long long> v(n + 1);
  v[0] = -1;
  long long i = 0, j = -1;
  while (i < n) {
    while (j >= 0 and t[i] != t[j]) j = v[j];
    i++, j++;
    v[i] = j;
  };
  for (i = 0; i < min(n, m); i++) {
    if (cnt[t[i % n] - '0']) {
      cout << t[i % n];
      cnt[t[i % n] - '0']--;
    } else
      break;
  }
  t = t.substr(v[n]);
  n = t.size();
  i = 0;
  while (cnt[0] and cnt[1]) {
    if (cnt[t[i % n] - '0']) {
      cout << t[i % n];
      cnt[t[i % n] - '0']--;
      i++;
    } else
      break;
  }
  while (cnt[0]--) cout << 0;
  while (cnt[1]--) cout << 1;
  return 0;
}
