#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 1e5 + 5;
int pi[N];
void build(string &s) {
  int len = s.length();
  for (int i = 1; i < len; i++) {
    int j = pi[i - 1];
    while (j > 0 && s[j] != s[i]) j = pi[j - 1];
    if (s[j] == s[i])
      pi[i] = 1 + j;
    else
      pi[i] = 0;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  build(t);
  int len = t.length();
  t = t.substr(0, len - pi[len - 1]);
  int has0 = 0, has1 = 0, need0 = 0, need1 = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '0')
      has0++;
    else
      has1++;
  }
  for (int i = 0; t[i]; i++) {
    if (t[i] == '0')
      need0++;
    else
      need1++;
  }
  string ans = "";
  while (has0 >= need0 && has1 >= need1) {
    has0 -= need0;
    has1 -= need1;
    ans += t;
  }
  string last = "";
  for (int i = 0; t[i]; i++) {
    if (t[i] == '0' && has0) {
      last += '0';
      has0--;
    } else if (t[i] == '1' && has1) {
      last += '1';
      has1--;
    } else
      break;
  }
  ans += (last + string(has0, '0') + string(has1, '1'));
  cout << ans << '\n';
  return 0;
}
