#include <bits/stdc++.h>
using namespace std;
int lps(string s) {
  int n = s.length();
  int lps[n];
  lps[0] = 0;
  int i = 1;
  int j = 0;
  while (i < n) {
    if (s[i] == s[j]) {
      lps[i] = j + 1;
      i++;
      j++;
    } else {
      if (j != 0)
        j = lps[j - 1];
      else {
        lps[i] = 0;
        i++;
      }
    }
  }
  return lps[n - 1];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string s;
  string t;
  cin >> s >> t;
  int a = count(s.begin(), s.end(), '0');
  int b = count(s.begin(), s.end(), '1');
  int c = count(t.begin(), t.end(), '0');
  int d = count(t.begin(), t.end(), '1');
  int e;
  if (c == 0)
    e = b / d;
  else if (d == 0)
    e = a / c;
  else
    e = min(a / c, b / d);
  if (e == 0)
    cout << s;
  else {
    cout << t;
    ;
    int f = lps(t);
    a = a - c;
    b = b - d;
    c = count(t.begin() + f, t.end(), '0');
    d = count(t.begin() + f, t.end(), '1');
    e = 0;
    if (c == 0)
      e = b / d;
    else if (d == 0)
      e = a / c;
    else
      e = min(a / c, b / d);
    a = a - e * c;
    b = b - d * e;
    for (int j = 0; j < e; j += 1) cout << t.substr(f);
    ;
    for (int j = 0; j < a; j += 1) cout << '0';
    for (int j = 0; j < b; j += 1) cout << '1';
  }
  cout << endl;
}
