#include <bits/stdc++.h>
using namespace std;
const int N = 500006;
int pi[N], f[2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i += 1) {
    f[s[i] - '0'] += 1;
  }
  string t;
  cin >> t;
  for (int i = 1; i < t.size(); i += 1) {
    int j = pi[i - 1];
    while (j > 0 && t[i] != t[j]) {
      j = pi[j - 1];
    }
    if (t[i] == t[j]) j += 1;
    pi[i] = j;
  }
  string ans = t;
  for (int i = 0; i < t.size(); i += 1) {
    if (!f[t[i] - '0']) {
      cout << s << '\n';
      return 0;
    }
    f[t[i] - '0'] -= 1;
  }
  int sz = pi[t.size() - 1];
  bool B = true;
  while (B) {
    for (int i = sz; i < t.size(); i++) {
      if (f[t[i] - '0'] == 0) {
        B = false;
        break;
      }
      ans.push_back(t[i]);
      f[t[i] - '0'] -= 1;
    }
  }
  for (int c = 0; c <= 1; c += 1) {
    for (int j = 1; j <= f[c]; j += 1) {
      ans.push_back(c + '0');
    }
    f[c] = 0;
  }
  cout << ans << '\n';
  return 0;
}
