#include <bits/stdc++.h>
using namespace std;
vector<int> Prefix(const string& s) {
  vector<int> ans(s.length(), 0);
  ans[0] = 0;
  for (int i = 1; i < s.length(); ++i) {
    int k = ans[i - 1];
    while (k > 0 && s[i] != s[k]) k = ans[k - 1];
    if (s[i] == s[k]) ++k;
    ans[i] = k;
  }
  return ans;
}
int main() {
  string s, t;
  getline(cin, s);
  getline(cin, t);
  string ans;
  int zero = 0;
  int one = 0;
  for (char c : s) {
    if (c == '0')
      ++zero;
    else
      ++one;
  }
  int prefix = Prefix(t).back();
  int k = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (zero == 0) {
      for (int j = 0; j < one; ++j) ans.push_back('1');
      break;
    } else if (one == 0) {
      for (int j = 0; j < zero; ++j) ans.push_back('0');
      break;
    } else {
      ans.push_back(t[k]);
      if (t[k] == '0')
        --zero;
      else
        --one;
      ++k;
      if (k >= t.length()) {
        if (prefix)
          k = prefix;
        else
          k = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
