import java.io.IOException;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		PrintWriter out = new PrintWriter(System.out);
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		//System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}else{
			out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int f = c==0?1000000:p/c;
			int g = d==0?1000000:q/d;
			int min = Math.min(f,g);
			for(int i=0;i<min;i++){
				out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}
		out.flush();
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long ah3 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long bh3 = 0;
		long t1 = 1;
		long t2 = 1;
		long t3 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int mod = 998244353;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah1 %= mod;
			ah2 = ah2 + a.charAt(l-i) * t2;
			ah2 %= mod;
			bh1 = bh1 * A + b.charAt(i-1);
			bh1 %= mod;
			bh2 = bh2 * B + b.charAt(i-1);
			bh2 %= mod;
			if(ah1==bh1&&ah2==bh2&&ah3==bh3){
				ans = i;
			}
			t1 *= A;
			t1 %= mod;
			t2 *= B;
			t2  %= mod;

		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		PrintWriter out = new PrintWriter(System.out);
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		//System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}else{
			out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int f = c==0?1000000:p/c;
			int g = d==0?1000000:q/d;
			int min = Math.min(f,g);
			for(int i=0;i<min;i++){
				out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}
		out.flush();
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long ah3 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long bh3 = 0;
		long t1 = 1;
		long t2 = 1;
		long t3 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int C = 998244353;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah2 = ah2 + a.charAt(l-i) * t2;
			ah3 = ah3 + a.charAt(l-i) * t3;
			bh1 = bh1 * A + b.charAt(i-1);
			bh2 = bh2 * B + b.charAt(i-1);
			bh3 = bh3 * C + b.charAt(i-1);
			if(ah1==bh1&&ah2==bh2&&ah3==bh3){
				ans = i;
			}
			t1 *= A;
			t2 *= B;
			t3 *= C;
		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


import java.io.IOException;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();

		char[] a1 = sc.nextString().toCharArray();
		char[] a2 = sc.nextString().toCharArray();
		int[] z = computeZArray(a2);

		int len = 0;
		for (int i = z.length - 1; i > 0; i--) {
			if (z.length - z[i] == i)
				len = Math.max(len, z[i]);
		}
		int[] cnt = new int[2];
		for (char c : a1)
			cnt[c - '0']++;
		StringBuffer sb = new StringBuffer();

		int i = 0;
		while (cnt[a2[i] - '0']-- > 0) {
			sb.append(a2[i] - '0');
			i++;
			if (i == a2.length)
				i = len;
		}
		while (cnt[0]-- > 0)
			sb.append('0');
		while (cnt[1]-- > 0)
			sb.append('1');

		System.out.println(sb.toString());
	}

	static int[] computeZArray(char[] s) {
		int[] z = new int[s.length];
		int L = 0, R = 0;
		for (int i = 1; i < s.length; i++) {
			if (i > R) {
				L = R = i;
				while (R < s.length && s[R - L] == s[R])
					R++;
				z[i] = R - L;
				R--;
			} else {
				int k = i - L;
				if (z[k] < R - i + 1)
					z[i] = z[k];
				else {
					L = i;
					while (R < s.length && s[R - L] == s[R])
						R++;
					z[i] = R - L;
					R--;
				}
			}
		}
		return z;
	}

	public static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = System.in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[][] nextInts(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextInt();
			}
			return arr;
		}

		public int[] nextIntArray(int n, int offset) {
			int[] arr = new int[n + offset];
			for (int i = 0; i < n; i++) {
				arr[i + offset] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLong();
			}
			return arr;
		}

		public long[] nextLongArray(int n, int offset) {
			long[] arr = new long[n + offset];
			for (int i = 0; i < n; i++) {
				arr[i + offset] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}
}


import javafx.scene.layout.Priority;
import java.io.*;
import java.lang.reflect.Array;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class templ implements Runnable{
    static class pair implements Comparable
    {
        int f;
        int s;
        pair(int fi,int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)
        {
            pair pr=(pair)o;
            if(s>pr.s)
                return 1;
            if(s==pr.s)
            {
                if(f>pr.f)
                    return 1;
                else
                    return -1;
            }
            else
                return -1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            int ff;
            int ss;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                if((ff==this.f)&&(ss==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f,t;
        int s;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            int ff;
            int ss;
            int tt;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                tt=ob.t;
                if((ff==this.f)&&(ss==this.s)&&(tt==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)
        {
            triplet tr=(triplet)o;
            if(t>tr.t)
                return 1;
            else
                return -1;
        }
    }
    void merge1(int arr[], int l, int m, int r)
    {
        int n1 = m - l + 1;
        int n2 = r - m;
        int L[] = new int [n1];
        int R[] = new int [n2];
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i]<=R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    void sort1(int arr[], int l, int r)
    {
        if (l < r)
        {
            int m = (l+r)/2;
            sort1(arr, l, m);
            sort1(arr , m+1, r);
            merge1(arr, l, m, r);
        }
    }
    int[] kmpsearch(String s)
    {
        int n=s.length();
        int lps[]=new int[n+1];
        lps[0]=0;
        int border=0;
        for(int i=1;i<n;i++)
        {
            while(border>0 && s.charAt(i)!=s.charAt(border))
                border=lps[border-1];
            if(s.charAt(i)==s.charAt(border))
                border=border+1;
            else
                border=0;
            lps[i]=border;
        }
        return lps;
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new templ(),"templ",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            String s=in.nextLine();
            String t=in.nextLine();
            int n1=s.length();
            int n2=t.length();
            int lps[]=kmpsearch(t);
            int x=0,y=0;
            for(int i=0;i<n1;i++)
            {
                char c=s.charAt(i);
                if(c=='0')
                    x++;
                else
                    y++;
            }
            StringBuilder sb=new StringBuilder();
            int z=0;
            while(true)
            {
                for(int i=z;i<n2;i++)
                {
                    char c=t.charAt(i);
                    if(c=='0')
                    {
                        if(x>0)
                        {
                            x--;
                            sb.append('0');
                        }
                        else
                        {
                            for(int ii=1;ii<=y;ii++)
                                sb.append('1');
                            y=0;
                        }
                    }
                    if(c=='1')
                    {
                        if(y>0)
                        {
                            y--;
                            sb.append('1');
                        }
                        else
                        {
                            for(int ii=1;ii<=x;ii++)
                                sb.append('0');
                            x=0;
                        }
                    }
                }
                if(x==0&&y==0)
                    break;
                z=lps[n2-1];
            }
            out.println(sb);
            out.close();
        }
        catch(Exception e){
            return;
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve(){
        s=ns().toCharArray();
        t=ns().toCharArray();
        computeLPS();
        int n=t.length;
        int c1[]=new int[2];
        int c2[]=new int[2];
        for(char ch : s) c1[ch-'0']++;
        for(char ch : t) c2[ch-'0']++;
        int l=lps[n-1];
        if(s.length<t.length || c1[1]<c2[1] || c1[0]<c2[0]){
            pw.println(new String(s));
            return;
        }
      //  pw.println(l);
        pw.print(new String(t));
        for(int i=0;i<n;i++) c2[t[i]-'0']--;
        while(c1[0]>=c2[0] && c1[1]>=c2[1]){
            for(int i=l;i<n;i++){
                c1[t[i]-'0']--;
                pw.print(t[i]);
            }
        }
        while(c1[0]-->0) pw.print("0");
        while(c1[1]-->0) pw.print("1");
        pw.println("");

    }
    char s[],t[];
    int lps[];
    void computeLPS(){
        int n=t.length;
        lps=new int[n];
        for(int i=1;i<n;i++){
            int j=lps[i-1];
            while(j>0 && t[i]!=t[j]){
                j=lps[j-1];
            }
            if(t[i]==t[j]) j++;
            lps[i]=j;
        }
    }
    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve(){
        s=ns().toCharArray();
        t=ns().toCharArray();
        computeLPS();
        int n=t.length;
        int c1[]=new int[2];
        int c2[]=new int[2];
        for(char ch : s) c1[ch-'0']++;
        for(char ch : t) c2[ch-'0']++;
        int l=lps[n-1];
        if(s.length<t.length || c1[1]<c2[1] || c1[0]<c2[0]){
            pw.println(new String(s));
            return;
        }
      //  pw.println(l);
        pw.print(new String(t));
        for(int i=0;i<l;i++) c2[t[i]-'0']--;
        for(int i=0;i<n;i++) c1[t[i]-'0']--;
        while(c1[0]>=c2[0] && c1[1]>=c2[1]){
            for(int i=l;i<n;i++){
                c1[t[i]-'0']--;
                pw.print(t[i]);
            }
        }
        while(c1[0]-->0) pw.print("0");
        while(c1[1]-->0) pw.print("1");
        pw.println("");

    }
    char s[],t[];
    int lps[];
    void computeLPS(){
        int n=t.length;
        lps=new int[n];
        for(int i=1;i<n;i++){
            int j=lps[i-1];
            while(j>0 && t[i]!=t[j]){
                j=lps[j-1];
            }
            if(t[i]==t[j]) j++;
            lps[i]=j;
        }
    }
    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TaskD {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String s = br.readLine();
        String t = br.readLine();

        int s0 = count(s, '0');
        int s1 = count(s, '1');
        int t0 = count(t, '0');
        int t1 = count(t, '1');

        if (t0 > s0 || t1 > s1) {
            System.out.println(s);
        } else {
            int tp = maxPrefixSuffix(t);
            String tail = t.substring(tp);
            int tail0 = count(tail, '0');
            int tail1 = count(tail, '1');

            int l0 = s0;
            int l1 = s1;
            StringBuilder result = new StringBuilder();
            result.append(t);
            l0 -= t0;
            l1 -= t1;

            while (l0 >= tail0 && l1 >= tail1) {
                result.append(tail);
                l0 -= tail0;
                l1 -= tail1;
            }
            while (l0 >= 0) {
                result.append('0');
                l0 -= 1;
            }
            while (l1 >= 0) {
                result.append('1');
                l1 -= 1;
            }
            System.out.println(result.toString());
        }

        br.close();
    }

    private static int count(String s, char wantedChar) {
        return (int) s.chars().filter(ch -> ch == wantedChar).count();
    }

    private static int maxPrefixSuffix(String str) {
        int[] p = new int[str.length()];
        p[0] = 0;
        for (int i = 1; i < str.length(); i++) {
            int j = p[i - 1];
            while (j > 0 && str.charAt(j) != str.charAt(i)) {
                j = p[j];
            }
            if (str.charAt(j) == str.charAt(i)) {
                j++;
            }
            p[i] = j;
        }
        return p[str.length() - 1];
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TaskD {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String s = br.readLine();
        String t = br.readLine();

        int s0 = count(s, '0');
        int s1 = count(s, '1');
        int t0 = count(t, '0');
        int t1 = count(t, '1');

        if (t0 > s0 || t1 > s1) {
            System.out.println(s);
        } else {
            int tp = maxPrefixSuffix(t);
            String tail = t.substring(tp);
            int tail0 = count(tail, '0');
            int tail1 = count(tail, '1');

            int l0 = s0;
            int l1 = s1;
            StringBuilder result = new StringBuilder();
            result.append(t);
            l0 -= t0;
            l1 -= t1;

            while (l0 >= tail0 && l1 >= tail1) {
                result.append(tail);
                l0 -= tail0;
                l1 -= tail1;
            }
            while (l0 > 0) {
                result.append('0');
                l0 -= 1;
            }
            while (l1 > 0) {
                result.append('1');
                l1 -= 1;
            }
            System.out.println(result.toString());
        }

        br.close();
    }

    private static int count(String s, char wantedChar) {
        return (int) s.chars().filter(ch -> ch == wantedChar).count();
    }

    private static int maxPrefixSuffix(String str) {
        int[] p = new int[str.length()];
        p[0] = 0;
        for (int i = 1; i < str.length(); i++) {
            int j = p[i - 1];
            while (j > 0 && str.charAt(j) != str.charAt(i)) {
                j = p[j - 1];
            }
            if (str.charAt(j) == str.charAt(i)) {
                j++;
            }
            p[i] = j;
        }
        return p[str.length() - 1];
    }
}


#include <bits/stdc++.h>

using namespace std;

int main () {
	string a;
	cin >> a;

	array<int, 2> cnt;
	cnt[0] = count(a.begin(), a.end(), '0');
	cnt[1] = count(a.begin(), a.end(), '1');

	string str;
	cin >> str;

	auto cmp_and_sub = [&](char&& c) {
		int ccnt = count(str.begin(), str.end(), c);
		return (cnt[c - '0'] -= ccnt) >= 0;
	};

	if (!cmp_and_sub('0') || !cmp_and_sub('1')) {
		cout << str << endl;
		return 0;
	}

	vector<int> p(str.size());
	p[0] = 0;
	for (int i = 1, k = 0; i < str.size(); ++i) {
		while (k > 0 && str[i] != str[k] && k > 0) {
			k = p[k - 1];
		}
		if (str[i] == str[k]) {
			k++;
		}
		p[i] = k;
	}

	int max_len = p.back();
	string suffix = str.substr(max_len);
	assert(suffix.size() == str.size() - max_len);

	array<int, 2> need_cnt;
	need_cnt[0] = count(suffix.begin(), suffix.end(), '0');
	need_cnt[1] = count(suffix.begin(), suffix.end(), '1');

	int add = min(need_cnt[0] == 0 ? numeric_limits<int>::max() : cnt[0] / need_cnt[0],
					need_cnt[1] == 0 ? numeric_limits<int>::max() : cnt[1] / need_cnt[1]);

	string ans{str};
	for (int i = 0; i < add; i++) {
		ans += suffix;
	}
	ans += string(cnt[0] - add * need_cnt[0], '0');
	ans += string(cnt[1] - add * need_cnt[1], '1');
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main () {
	string a;
	cin >> a;

	array<int, 2> cnt;
	cnt[0] = count(a.begin(), a.end(), '0');
	cnt[1] = count(a.begin(), a.end(), '1');

	string str;
	cin >> str;

	auto cmp_and_sub = [&](char&& c) {
		int ccnt = count(str.begin(), str.end(), c);
		return (cnt[c - '0'] -= ccnt) >= 0;
	};

	if (!cmp_and_sub('0') || !cmp_and_sub('1')) {
		cout << a << endl;
		return 0;
	}

	vector<int> p(str.size());
	p[0] = 0;
	for (int i = 1, k = 0; i < str.size(); ++i) {
		while (k > 0 && str[i] != str[k] && k > 0) {
			k = p[k - 1];
		}
		if (str[i] == str[k]) {
			k++;
		}
		p[i] = k;
	}

	int max_len = p.back();
	string suffix = str.substr(max_len);
	assert(suffix.size() == str.size() - max_len);

	array<int, 2> need_cnt;
	need_cnt[0] = count(suffix.begin(), suffix.end(), '0');
	need_cnt[1] = count(suffix.begin(), suffix.end(), '1');

	int add = min(need_cnt[0] == 0 ? numeric_limits<int>::max() : cnt[0] / need_cnt[0],
					need_cnt[1] == 0 ? numeric_limits<int>::max() : cnt[1] / need_cnt[1]);

	string ans{str};
	for (int i = 0; i < add; i++) {
		ans += suffix;
	}
	ans += string(cnt[0] - add * need_cnt[0], '0');
	ans += string(cnt[1] - add * need_cnt[1], '1');
	cout << ans << endl;
}


//In the name of allah the most merciful.
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define N 100005
#define INF 1e9

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    string a,b;
    cin>>a>>b;
    if(b.length()>a.length())
     {
     	cout<<a<<endl;
     	return 0;
	 }

	 int lcp[b.length()];
	 lcp[0]=0;
	 for(int i=1;i<b.length();i++)
	 {
	 	int j=lcp[i-1];
	 	while(j>0 && b[j]!=b[i])
	 	 j=lcp[j-1];

	 	 if(b[j]==b[i])
	 	  j++;
	 	  lcp[i]=j;
	 }

	 int x=lcp[int(b.length())-1];
     // if(x==b.length()-1)
       // x++;

	 int ca2=0,cb2=0;
	 for(int i=0;i<x;i++)
	  {
	  	if(b[i]=='1')
	  	 ca2++;
	  	 else
	  	 cb2++;
	  }

	 int ca=0,cb=0;
	 for(int i=0;i<a.length();i++)
	  {
	  	if(a[i]=='1')
	  	 ca++;
	  	 else
	  	 cb++;
	  }
	  int ca1=0,cb1=0;
	  for(int i=0;i<b.length();i++)
	  {
	  	if(b[i]=='1')
	  	 ca1++;
	  	 else
	  	 cb1++;
	  }

	 string ans="";
	 if(ca-ca1>=0 && cb-cb1>=0)
	  {
	    ans+=b;
	    ca-=ca1;
	 	cb-=cb1;
     }

     string kaif="";
     for(int i=x;i<b.length();i++)
      kaif+=b[i];

     ca1-=ca2;
     cb1-=cb2;
	 while(ca-ca1>=0 && cb-cb1>=0 && ans.length()>0)
	 {
	 	ans+=kaif;
	 	ca-=ca1;
	 	cb-=cb1;
	 }
	  while(ca>0)
	   {
	   ans+='1';
	    ca--;
       }
	   while(cb>0)
	    {
		ans+='0';
		cb--;
	    }
	  cout<<ans;

 	return 0;
}


//In the name of allah the most merciful.
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define N 100005
#define INF 1e9

using namespace std;

void lps(string & pat,int m,int lps1[])
{
	int len=0,i=1;
	lps1[0]=0;
	while(i<m)
	{
		if(pat[i]==pat[len])
		{
			len++;
			lps1[i]=len;
			i++;
		}

		else
		{
			if(len!=0)
				len=lps1[len-1];

			else
			{
			    lps1[i]=0;
				i++;
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    string a,b;
    cin>>a>>b;
    if(b.length()>a.length())
     {
     	cout<<a<<endl;
     	return 0;
	 }

	 int arr[b.length()];
	 lps(b,b.length(),arr);

	 int x=arr[int(b.length())-1];

	 int ca2=0,cb2=0;
	 for(int i=0;i<x;i++)
	  {
	  	if(b[i]=='1')
	  	 ca2++;
	  	 else
	  	 cb2++;
	  }

	 int ca=0,cb=0;
	 for(int i=0;i<a.length();i++)
	  {
	  	if(a[i]=='1')
	  	 ca++;
	  	 else
	  	 cb++;
	  }
	  int ca1=0,cb1=0;
	  for(int i=0;i<b.length();i++)
	  {
	  	if(b[i]=='1')
	  	 ca1++;
	  	 else
	  	 cb1++;
	  }

	 string ans="";
	 if(ca-ca1>=0 && cb-cb1>=0)
	  {
	    ans+=b;
	    ca-=ca1;
	 	cb-=cb1;
     }

     string kaif="";
     for(int i=x;i<b.length();i++)
      kaif+=b[i];

	 while(ca-ca1+ca2>=0 && cb-cb1+cb2>=0)
	 {
	 	ans+=kaif;
	 	ca-=(ca1+ca2);
	 	cb-=(cb1+cb2);
	 }
	  while(ca>0)
	   {
	   ans+='1';
	    ca--;
       }
	   while(cb>0)
	    {
		ans+='0';
		cb--;
	    }
	  cout<<ans;
 	return 0;
}


//In the name of allah the most merciful.
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define N 100005
#define INF 1e9

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    string a,b;
    cin>>a>>b;
    if(b.length()>a.length())
     {
     	cout<<a<<endl;
     	return 0;
	 }

	 int lcp[b.length()];
	 lcp[0]=0;
	 for(int i=1;i<b.length();i++)
	 {
	 	int j=lcp[i-1];
	 	while(j>0 && b[j]!=b[i])
	 	 j=lcp[j-1];

	 	 if(b[j]==b[i])
	 	  j++;
	 	  lcp[i]=j;
	 }

	 int x=lcp[int(b.length())-1];
     // if(x==b.length()-1)
       // x++;

	 int ca2=0,cb2=0;
	 for(int i=0;i<x;i++)
	  {
	  	if(b[i]=='1')
	  	 ca2++;
	  	 else
	  	 cb2++;
	  }

	 int ca=0,cb=0;
	 for(int i=0;i<a.length();i++)
	  {
	  	if(a[i]=='1')
	  	 ca++;
	  	 else
	  	 cb++;
	  }
	  int ca1=0,cb1=0;
	  for(int i=0;i<b.length();i++)
	  {
	  	if(b[i]=='1')
	  	 ca1++;
	  	 else
	  	 cb1++;
	  }

	 string ans="";
	 if(ca-ca1>=0 && cb-cb1>=0)
	  {
	    ans+=b;
	    ca-=ca1;
	 	cb-=cb1;
     }

     string kaif="";
     for(int i=x;i<b.length();i++)
      kaif+=b[i];

	 while(ca-(ca1+ca2)>=0 && cb-(cb1+cb2)>=0 && ans.length()>0)
	 {
	 	ans+=kaif;
	 	ca-=(ca1+ca2);
	 	cb-=(cb1+cb2);
	 }
	  while(ca>0)
	   {
	   ans+='1';
	    ca--;
       }
	   while(cb>0)
	    {
		ans+='0';
		cb--;
	    }
	  cout<<ans;

 	return 0;
}


//In the name of allah the most merciful.
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define N 100005
#define INF 1e9

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    string a,b;
    cin>>a>>b;
    if(b.length()>a.length())
     {
     	cout<<a<<endl;
     	return 0;
	 }

	 int ca=0,cb=0;
	 for(int i=0;i<a.length();i++)
	  {
	  	if(a[i]=='1')
	  	 ca++;
	  	 else
	  	 cb++;
	  }
	  int ca1=0,cb1=0;
	  for(int i=0;i<b.length();i++)
	  {
	  	if(b[i]=='1')
	  	 ca1++;
	  	 else
	  	 cb1++;
	  }

	 string ans="";
	 while(ca-ca1>0 && cb-cb1>0)
	 {
	 	ans+=b;
	 	ca-=ca1;
	 	cb-=cb1;
	 }
	  while(ca>0)
	   {
	   ans+='1';
	    ca--;
        }
	   while(cb>0)
	    {
		ans+='0';
		cb--;
	    }
	  cout<<ans;
 	return 0;
}


//In the name of allah the most merciful.
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define N 100005
#define INF 1e9

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    string a,b;
    cin>>a>>b;
    if(b.length()>a.length())
     {
     	cout<<a<<endl;
     	return 0;
	 }

	 int lcp[b.length()];
	 lcp[0]=0;
	 for(int i=1;i<b.length();i++)
	 {
	 	int j=lcp[i-1];
	 	while(j>0 && b[j]!=b[i])
	 	 j=lcp[j-1];

	 	 if(b[j]==b[i])
	 	  j++;
	 	  lcp[i]=j;
	 }

	 int x=lcp[int(b.length())-1];

	 int ca2=0,cb2=0;
	 for(int i=0;i<x;i++)
	  {
	  	if(b[i]=='1')
	  	 ca2++;
	  	 else
	  	 cb2++;
	  }

	 int ca=0,cb=0;
	 for(int i=0;i<a.length();i++)
	  {
	  	if(a[i]=='1')
	  	 ca++;
	  	 else
	  	 cb++;
	  }
	  int ca1=0,cb1=0;
	  for(int i=0;i<b.length();i++)
	  {
	  	if(b[i]=='1')
	  	 ca1++;
	  	 else
	  	 cb1++;
	  }

	 string ans="";
	 if(ca-ca1>=0 && cb-cb1>=0)
	  {
	    ans+=b;
	    ca-=ca1;
	 	cb-=cb1;
     }

     string kaif="";
     for(int i=x;i<b.length();i++)
      kaif+=b[i];

	 while(ca-ca1+ca2>=0 && cb-cb1+cb2>=0 && ans.length()>0)
	 {
	 	ans+=kaif;
	 	ca-=(ca1+ca2);
	 	cb-=(cb1+cb2);
	 }
	  while(ca>0)
	   {
	   ans+='1';
	    ca--;
       }
	   while(cb>0)
	    {
		ans+='0';
		cb--;
	    }
	  cout<<ans;

 	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    for(int i = 0;i < m - 1;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + qPow(t[m-i-1] - '0', i)) % MOD;
        if(valS == valT) ans = i+1;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    for(int i = 0;i < m - 1;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + (t[m-i-1] - '0')*qPow(2, i)) % MOD;
        if(valS == valT) ans = i+1;
        //cout << valS << " " << valT << endl;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    //std::cout << ans << endl;
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 19260817;

char s[MAXN], t[MAXN];
int n, m;

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    int sa = 0, sb = 0, na = 0, nb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') na++;
        else nb++;
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    int nuA = na == 0 ? MAXN : sa/na;
    int nuB = nb == 0 ? MAXN : sb/nb;
    int num = min(nuA, nuB);
    for(int i = 0;i < num;i++) {
        std::cout << t;
    }
    sa -= na*num, sb -= nb*num;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 9;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

int main() {
    cin >> s >> t;
    n = strlen(s), m = strlen(t);
    LL valS = 0, valT = 0, POW = 1;
    int ans = 0;
    for(int i = 0;i < m - 1;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + (t[m-i-1] - '0')*POW) % MOD;
        if(valS == valT) ans = i+1;
        POW = (POW << 1) % MOD;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') na++, ta += (i >= ans);
        else nb++, tb += (i >= ans);
    }
    if(sa < na || sb < nb) {
        cout << s << endl;
        return 0;
    }
    cout << t;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) cout << t[j];
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) cout << '0';
    for(int i = 1;i <= sb;i++) cout << '1';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 19260817;

char s[MAXN], t[MAXN];
int n, m;

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    int sa, sb, na, nb;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') na++;
        else nb++;
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    int num = min(sa/na, sb/nb);
    for(int i = 0;i < num;i++) {
        std::cout << t;
    }
    sa -= na*num, sb -= nb*num;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    for(int i = 0;i < m;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + qPow(t[m-i-1] - '0', i)) % MOD;
        if(valS == valT) ans = i+1;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 19260817;

char s[MAXN], t[MAXN];
int n, m;

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    int sa = 0, sb = 0, na = 0, nb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') na++;
        else nb++;
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    int num = min(sa/na, sb/nb);
    for(int i = 0;i < num;i++) {
        std::cout << t;
    }
    sa -= na*num, sb -= nb*num;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    for(int i = 0;i < m;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + qPow(t[m-i-1] - '0', i)) % MOD;
        if(valS == valT) ans = i+1;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << "-" << endl;
        return 0;
    }
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 9;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    LL POW = 1;
    //std::cout << m << endl;
    for(int i = 0;i < m - 1;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + (t[m-i-1] - '0')*POW) % MOD;
        if(valS == valT) ans = i+1;
        POW = (POW << 1) % MOD;
        //cout << valS << " " << valT << " " << POW << endl;
    }
    //std::cout << ans << endl;
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    //std::cout << ans << endl;
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

char s[MAXN], t[MAXN];
int n, m;

LL qPow(LL x, LL a) {
    if(x == 0) return 0;
    LL res = 1;
    while(a) {
        if(a & 1) {
            res = (res*x) % MOD;
        }
        x = (x*x) % MOD;
        a >>= 1;
    }
    return res;
}

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    //int len = min(n, m);
    LL valS = 0, valT = 0;
    int ans = 0;
    for(int i = 0;i < m - 1;i++) {
        valS = (valS << 1) % MOD;
        valS = (valS + (t[i] - '0')) % MOD;
        valT = (valT + (t[m-i-1] - '0')*qPow(2, i)) % MOD;
        if(valS == valT) ans = i+1;
        //cout << valS << " " << valT << endl;
    }
    int sa = 0, sb = 0, na = 0, nb = 0, ta = 0, tb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') {
            na++;
            ta += (i >= ans);
        }
        else {
            nb++;
            tb += (i >= ans);
        }
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    //std::cout << ans << endl;
    std::cout << t;
    //std::cout << sa << " " << sb << " " << na << " " << nb << " " << ta << " " << tb << endl;
    sa -= na, sb -= nb;
    int num = min((ta == 0 ? INF : sa/ta), (tb == 0 ? INF : sb/tb));
    for(int i = 1;i <= num;i++) {
        for(int j = ans;j < m;j++) {
            std::cout << t[j];
        }
    }
    sa -= num*ta, sb -= num*tb;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 7;
typedef long long LL;
typedef long double LD;
const LL MOD = 19260817;

char s[MAXN], t[MAXN];
int n, m;

int main(int argc, char *argv[]) {
    std::cin >> s >> t;
    n = strlen(s), m = strlen(t);
    int sa = 0, sb = 0, na = 0, nb = 0;
    for(int i = 0;i < n;i++) {
        if(s[i] == '0') sa++;
        else sb++;
    }
    for(int i = 0;i < m;i++) {
        if(t[i] == '0') na++;
        else nb++;
    }
    if(sa < na || sb < nb) {
        std::cout << s << endl;
        return 0;
    }
    if(na == 0) na++;
    if(nb == 0) nb++;
    int num = min(sa/na, sb/nb);
    for(int i = 0;i < num;i++) {
        std::cout << t;
    }
    sa -= na*num, sb -= nb*num;
    for(int i = 1;i <= sa;i++) {
        std::cout << '0';
    }
    for(int i = 1;i <= sb;i++) {
        std::cout << '1';
    }
    std::cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int getLps(string &str)
{
	int n=str.length();
	vector<int> ans(n,0);
	int i=0,j=1;
	while(j<n)
	{
		if(str[i]==str[j])
		{
			ans[j]=i+1;
			i++;
		}
		else
		{
			while(i>0&&str[i]!=str[j])
			i=ans[i-1];
			if(str[i]==str[j])
			{
				ans[j]=i+1;
				i++;
			}
		}
		j++;
	}
	return ans[n-1];
}
int main()
{
    int test=1;
    //cin>>test;
    while(test--)
    {
    	string a,b;
    	cin>>a>>b;
    	int p=getLps(b);
    	//cout<<p<<endl;
    	string s=b.substr(p);
    	//cout<<s<<endl;
    	int t0=0,t1=0,b0=0,b1=0,a0=0,a1=0;
    	for(int i=0;i<a.length();i++)
    	{
    		if(a[i]=='0')
			a0++;
			else
			a1++;
		}
    	for(int i=0;i<b.length();i++)
    	{
    		if(b[i]=='0')
			{
				b0++;
				if(i<p)
				t0++;
			}
			else
			{
				b1++;
				if(i<p)
				t1++;
			}
		}
    	if(a0<b0||a1<b1)
    	{
    		cout<<a<<endl;
    		continue;
		}
		//cout<<a0<<" "<<b0<<" "<<a1<<" "<<b1<<" "<<t0<<" "<<t1<<endl;
		a0-=b0,a1-=b1;
		t0=b0-t0,t1=b1-t1;
		cout<<b;//<<endl;
		//cout<<a0<<" "<<t0<<" "<<a1<<" "<<t1<<endl;
		int m=0;
		int l=t0==0? INT_MAX:a0/t0;
		int k=t1==0? INT_MAX:a1/t1;
		m=min(l,k);
		for(int i=0;i<m;i++)
		cout<<s;
		if(l!=INT_MAX)
		{
			a0=a0-(a0/t0)*t0;
		}
		if(k!=INT_MAX)
		a1=a1-(a1/t1)*t1;
		for(int j=0;j<a1;j++)
			cout<<1;
  	for(int j=0;j<a0;j++)
			cout<<0;
		cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int getLps(string &str)
{
	int n=str.length();
	vector<int> ans(n,0);
	int i=0,j=1;
	while(j<n)
	{
		if(str[i]==str[j])
		{
			ans[j]=i+1;
			i++;
		}
		else
		{
			while(i>0&&str[i]!=str[j])
			i=ans[i-1];
			if(str[i]==str[j])
			{
				ans[j]=i+1;
				i++;
			}
		}
		j++;
	}
	return ans[n-1];
}
int main()
{
    int test=1;
    //cin>>test;
    while(test--)
    {
    	string a,b;
    	cin>>a>>b;
    	int p=getLps(b);
    	//cout<<p<<endl;
    	string s=b.substr(p);
    	//cout<<s<<endl;
    	int t0=0,t1=0,b0=0,b1=0,a0=0,a1=0;
    	for(int i=0;i<a.length();i++)
    	{
    		if(a[i]=='0')
			a0++;
			else
			a1++;
		}
    	for(int i=0;i<b.length();i++)
    	{
    		if(b[i]=='0')
			{
				b0++;
				if(i<p)
				t0++;
			}
			else
			{
				b1++;
				if(i<p)
				t1++;
			}
		}
    	if(a0<b0||a1<b1)
    	{
    		cout<<a<<endl;
    		continue;
		}
		//cout<<a0<<" "<<b0<<" "<<a1<<" "<<b1<<" "<<t0<<" "<<t1<<endl;
		a0-=b0,a1-=b1;
		t0=b0-t0,t1=b1-t1;
		cout<<b;//<<endl;
		//cout<<a0<<" "<<t0<<" "<<a1<<" "<<t1<<endl;
		int m=0;
		int l=t0==0? INT_MAX:a0/t0;
		int k=t1==0? INT_MAX:a1/t1;
		m=min(l,k);
		for(int i=0;i<m;i++)
		cout<<s;
		if(l!=INT_MAX)
		a0=a0-m*t0;
		if(k!=INT_MAX)
		a1=a1-m*t1;
	//	cout<<a0<<" "<<a1<<endl;
		for(int j=0;j<a1;j++)
		cout<<1;
  		for(int j=0;j<a0;j++)
		cout<<0;
		cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
void count(string &s,int &o,int &z)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='0')
		o++;
		else
		z++;
	}
}
int main()
{
//	int test=1;
//	while(test--)
//	{
		string s1,s2;
		cin>>s1>>s2;
		int o1=0,o2=0,z1=0,z2=0;
		count(s1,o1,z1);
		count(s2,o2,z2);
		int p_t=min(o1/o2,z1/z2);
		for(int i=0;i<p_t;i++)
		cout<<s2;
		int remo=0,remz=0;
		if(o1/o2>=z1/z2)
		{
			remz=z1%z2;
			remo=o1%o2+(o1/o2-z1/z2);
		}
		else
		{
			remo=o1%o2;
			remz=z1%z2+(z1/z2-o1/o2);
		}
		for(int i=0;i<remo;i++)
		cout<<'0';
		for(int i=0;i<remz;i++)
		cout<<'1';
		cout<<endl;
	//}
}


#include<bits/stdc++.h>
using namespace std;
void count(string &s,int &o,int &z)
{
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='0')
		z++;
		else
		o++;
	}
}
int main()
{
//	int test=1;
//	while(test--)
//	{
		string s1,s2;
		cin>>s1>>s2;
		int o1=0,o2=0,z1=0,z2=0;
		count(s1,o1,z1);
		count(s2,o2,z2);
		int p_t;
		if(o2&&z2)
  		{
  			p_t=min(o1/o2,z1/z2);
			for(int i=0;i<p_t;i++)
			cout<<s2;
			int remo=0,remz=0;
			if(o1/o2>=z1/z2)
			{
				remz=z1%z2;
				remo=o1%o2+(o1/o2-z1/z2);
			}
			else
			{
				remo=o1%o2;
				remz=z1%z2+(z1/z2-o1/o2);
			}
			for(int i=0;i<remz;i++)
			cout<<'0';
			for(int i=0;i<remo;i++)
			cout<<'1';
			cout<<endl;
		}
		else if(!o2&&!z2)
		cout<<s1<<endl;
		else if(!o2&&z2)
		{
			for(int i=0;i<z1/z2;i++)
			cout<<s2;
			for(int i=0;i<z1%z2;i++)
			cout<<'0';
			for(int i=0;i<o1;i++)
			cout<<'1';
			cout<<endl;
		//	cout<<"err";
		}
		else
		{
			for(int i=0;i<o1/o2;i++)
			cout<<s2;
			for(int i=0;i<z1;i++)
			cout<<'0';
			cout<<endl;
			for(int i=0;i<o1%o2;i++)
			cout<<'1';
		}
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]
void getZarr(string& str, vector<int>& Z)
{
    int n = str.length();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}
int main()
{
	string s,t;
	cin>>s>>t;
    vector<int> z(t.size(), 0);
    getZarr(t, z);
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forn(i, t.size())
    {
        if(i+1+z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1, or2;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
            if(t[i] == '1')
            {
                cnt1--;
            }
            else
                cnt2--;
        }
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]

int main()
{
	string s,t;
	cin>>s>>t;
    if(s.size() < t.size())
    {
        cout<<s<<'\n';
        return 0;
    }
    vector<int> Z(t.size(), 0);

    int n = t.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && t[R-L] == t[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && t[R-L] == t[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }

    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forsn(i, 1, t.size())
    {
        if(i+1+Z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1 = 0, or2 = 0;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]

int main()
{
	string s,t;
	cin>>s>>t;
    if(s.size() < t.size())
    {
        cout<<s<<'\n';
        return 0;
    }
    vector<int> Z(t.size(), 0);

    int n = t.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && t[R-L] == t[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && t[R-L] == t[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }

    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forsn(i, 1, t.size())
    {
        if(i+Z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1 = 0, or2 = 0;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, t.size()-req1-req2, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]

int main()
{
	string s,t;
	cin>>s>>t;
    if(s.size() < t.size())
    {
        cout<<s<<'\n';
        return 0;
    }
    vector<int> Z(t.size(), 0);

    int n = t.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && t[R-L] == t[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && t[R-L] == t[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }

    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forsn(i, 1, t.size())
    {
        if(i+Z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1 = 0, or2 = 0;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]
void getZarr(string str, vector<int>& Z)
{
    int n = str.length();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}
int main()
{
	string s,t;
	cin>>s>>t;
    vector<int> z(t.size(), 0);
    getZarr(t, z);
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = -1;
    forn(i, t.size())
    {
        if(i+1+z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1, or2;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            req1++;
        }
        else
        {
            req2++;
        }
    }
    or1 = req1;
    or2 = req2;
    if(l != -1)
    {
        forsn(i, l, t.size())
        {
            if(t[i] == '1')
            {
                req1--;
            }
            else
            {
                req2--;
            }
        }
    }
    vector<int> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
            if(t[i] == '1')
            {
                cnt1--;
            }
            else
                cnt2--;
        }
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]

int main()
{
	string s,t;
	cin>>s>>t;
    cout<<s.size()<<" "<<t.size()<<'\n';
    if(s.size() < t.size())
    {
        cout<<s<<'\n';
        return 0;
    }
    vector<int> Z(t.size(), 0);

    int n = t.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && t[R-L] == t[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && t[R-L] == t[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }

    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forsn(i, 1, t.size())
    {
        if(i+1+Z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1 = 0, or2 = 0;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]
void getZarr(string str, vector<int>& Z)
{
    int n = str.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}
int main()
{
	string s,t;
	cin>>s>>t;
    vector<int> z(t.size(), 0);
    getZarr(t, z);
    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forn(i, t.size())
    {
        if(i+1+z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1, or2;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]
void getZarr(string str, vector<int>& Z)
{
    int n = str.length();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}
int main()
{
	string s,t;
	cin>>s>>t;
    vector<int> z(t.size(), 0);
    getZarr(t, z);
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = -1;
    forn(i, t.size())
    {
        if(i+1+z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1, or2;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            req1++;
        }
        else
        {
            req2++;
        }
    }
    or1 = req1;
    or2 = req2;
    if(l != -1)
    {
        forsn(i, l, t.size())
        {
            if(t[i] == '1')
            {
                req1--;
            }
            else
            {
                req2--;
            }
        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
            if(t[i] == '1')
            {
                cnt1--;
            }
            else
                cnt2--;
        }
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1000000007;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

// Fills Z array for given string str[]

int main()
{
	string s,t;
	cin>>s>>t;
    if(s.size() < t.size())
    {
        cout<<s<<'\n';
        return 0;
    }
    vector<int> Z(t.size(), 0);

    int n = t.size();
    int L, R, k;

    // [L,R] make a window which matches with prefix of s
    L = R = 0;
    for (int i = 1; i < n; ++i)
    {
        // if i>R nothing matches so we will calculate.
        // Z[i] using naive way.
        if (i > R)
        {
            L = R = i;

            // R-L = 0 in starting, so it will start
            // checking from 0'th index. For example,
            // for "ababab" and i = 1, the value of R
            // remains 0 and Z[i] becomes 0. For string
            // "aaaaaa" and i = 1, Z[i] and R become 5
            while (R<n && t[R-L] == t[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            // k = i-L so k corresponds to number which
            // matches in [L,R] interval.
            k = i-L;

            // if Z[k] is less than remaining interval
            // then Z[i] will be equal to Z[k].
            // For example, str = "ababab", i = 3, R = 5
            // and L = 2
            if (Z[k] < R-i+1)
                Z[i] = Z[k];

            // For example str = "aaaaaa" and i = 2, R is 5,
            // L is 0
            else
            {
                // else start from R and check manually
                L = i;
                while (R<n && t[R-L] == t[R])
                    R++;
                Z[i] = R-L;
                R--;
            }
        }
    }

    /*
    cout<<s<<" "<<t<<'\n';
    forn(i, t.size())
    {
        cout<<z[i]<<" ";
    }
    cout<<'\n'; */
    int cnt1 = 0, cnt2 = 0;
    forn(i, s.size())
    {
        if(s[i] == '1')
        {
            cnt1++;
        }
        else
        {
            cnt2++;
        }
    }
    int l = t.size();
    forsn(i, 1, t.size())
    {
        if(i+1+Z[i] == t.size())
        {
            l = i;
            break;
        }
    }
    int req1 = 0, req2 = 0, or1, or2;
    forn(i, t.size())
    {
        if(t[i] == '1')
        {
            or1++;
        }
        else
        {
            or2++;
        }
        if(i >= t.size()-l)
        {
            if(t[i] == '1')
            {
                req1++;
            }
            else
            {
                req2++;
            }

        }
    }
    vector<bool> fn;
    if(or1 <= cnt1 && or2 <= cnt2)
    {
        forn(i, t.size())
        {
            fn.pb(t[i]-'0');
        }
        cnt1 -= or1;
        cnt2 -= or2;
    }
    while(cnt1 >= req1 && cnt2 >= req2)
    {
        cnt1 -= req1;
        cnt2 -= req2;
        forsn(i, req1+req2-1, t.size())
        {
            fn.pb(t[i]-'0');
        }
    }
    forn(i, cnt1)
    {
        fn.pb(1);
    }
    forn(i, cnt2)
    {
        fn.pb(0);
    }
    forn(i, s.size())
    {
        cout<<fn[i];
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll,ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll expo(ll base, ll exponent, ll md) {
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%md;
        }
        base = base*base;
        base %= md;
        exponent>>= 1;
    }
    return ans%md;
}
ll modInv(ll a, ll m) {
 	return expo(a,m-2,m);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,i,j,k,m,na,nb,nc,nd,aa,bb,cc,dd;
		string s,t,x,y,z,ss;
		cin>>s>>t;
		n=s.size();m=t.size();
		ll a[2],b[2];
		a[0]=0;a[1]=0;b[0]=0;b[1]=0;
		rep(i,0,n)
		{
			if(s[i]=='0')
			a[0]++;
			else
			a[1]++;
		}
		rep(i,0,m)
		{
			if(t[i]=='0')
			b[0]++;
			else
			b[1]++;
		}
		if(m>n || a[0]<b[0] || a[1]<b[1])
		{
			cout<<s;
			return 0;
		}
		ll I=-10;
		ll hash=937;
		ll pw=31;
		ll pdp[m+1],modi[m+1];
		rep(i,0,m+1)
		{
			pdp[i]=pw;
			modi[i]=modInv(pw,mod);
			pw=(pw*hash)%mod;
		}
		vec v(m+1,0);
		rep(i,0,m)
		{
			v[i+1]=((t[i]-'a'+1)*pdp[i])%mod;
		}
		rep(i,1,m+1)
		{
			v[i]=(v[i]+v[i-1])%mod;
		}
		ll xx,yy;
		rep(i,2,m+1)
		{
			xx=(((v[n]-v[i-1]+mod)%mod)*modi[i-1])%mod;
			yy=(((v[n-i-1]-v[0]+mod)%mod)*modi[0])%mod;
			if(xx==yy)
			{
				I=i-1;
				break;
			}
		}

	//	rep(i,1,m)
	//	{
	//		y=t.substr(i);
	//		z=t.substr(0,m-i);
	//		if(y==z)
	//		{
	//			I=i;
	//			break;
	//		}
	//	}
		if(I==-10)
		{
			while(true)
			{
				if(a[0]-b[0]>=0 && a[1]-b[1]>=0)
				{
					cout<<t;
					a[0]-=b[0];a[1]-=b[1];
				}
				else
				{
					rep(i,0,a[0])
					cout<<0;
					rep(i,0,a[1])
					cout<<1;
					a[0]=0;a[1]=0;
				}
				if(a[0]==0 && a[1]==0)
				break;
			}
		}
		else
		{
			ll x0=0;ll x1=0;
			rep(i,m-I,m)
			{
				if(t[i]=='0')
				x0++;
				if(t[i]=='1')
				x1++;
			}
			ss=t.substr(m-I);
			a[0]-=b[0];a[1]-=b[1];
			cout<<t;
			while(true)
			{
				if(a[0]-x0>=0 && a[1]-x1>=0 && x1!=0 && x0!=0)
				{
					ll mini=min(a[0]/x0,a[1]/x1);
					rep(i,0,mini)
					cout<<ss;
					a[0]-=x0*mini;a[1]-=x1*mini;
		    	}
		    	else if(a[0]-x0>=0 && a[1]-x1>=0 && x0==0 && x1!=0)
				{
					rep(i,0,a[1]/x1)
					cout<<ss;
					a[1]-=x1*(a[1]/x1);
		    	}
		    	else if(a[0]-x0>=0 && a[1]-x1>=0 && x0!=0 && x1==0)
				{
					rep(i,0,a[0]/x0)
					cout<<ss;
					a[0]-=x0*(a[0]/x0);
		    	}
					rep(i,0,a[0])
					cout<<0;
					rep(i,0,a[1])
					cout<<1;
				    break;
			}
		}
	}
	return 0;
}