#include <bits/stdc++.h>
template <typename T>
T gcd(T a, T b) {
  return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
namespace Problem {
using namespace std;
class Solver {
 public:
  string S, T;
  void solve() {
    cin >> S >> T;
    vector<int> A(T.size());
    A[0] = T.size();
    int i = 1, j = 0;
    while (i < T.size()) {
      while (i + j < T.size() && T[j] == T[i + j]) ++j;
      A[i] = j;
      if (j == 0) {
        ++i;
        continue;
      }
      int k = 1;
      while (i + k < T.size() && k + A[k] < j) A[i + k] = A[k], ++k;
      i += k;
      j -= k;
    }
    int res = 0, cnt0 = 0, cnt1 = 0, c0 = 0, c1 = 0;
    for (res = 1; res < (int)T.size(); ++res) {
      if (A[res] == (int)T.size() - res) {
        break;
      }
    }
    for (int i = 0; i < res; ++i) {
      if (T[i] == '0') {
        c0++;
      } else {
        c1++;
      }
    }
    for (int i = 0; i < S.size(); ++i) {
      if (S[i] == '0') {
        cnt0++;
      } else {
        cnt1++;
      }
    };
    ;
    string ans = "";
    if (c0 == 0 || c1 == 0) {
      for (int i = 0; i < cnt0; ++i) {
        ans += '0';
      }
      for (int i = 0; i < cnt1; ++i) {
        ans += '1';
      }
    } else {
      int loop = 0;
      for (loop = 0; loop < min(cnt0 / c0, cnt1 / c1); ++loop) {
        ans += T.substr(0, res);
      }
      cnt0 -= c0 * loop;
      cnt1 -= c1 * loop;
      for (int i = 0; i < res; ++i) {
        if (T[i] == '0' && cnt0 > 0) {
          ans += '0';
          cnt0--;
        } else if (T[i] == '1' && cnt1 > 0) {
          ans += '1';
          cnt1--;
        }
      }
      for (int i = 0; i < cnt0; ++i) {
        ans += '0';
      }
      for (int i = 0; i < cnt1; ++i) {
        ans += '1';
      }
    }
    cout << ans << endl;
  }
};
}  // namespace Problem
int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  Problem::Solver sol;
  sol.solve();
  return 0;
}
