#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 N         500005
#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 pdp[N],modi[N];
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;
		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[m]-v[i-1]+mod)%mod)*modi[i-1])%mod;
			yy=(((v[m-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;
}


#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;
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;
		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=-1;
		rep(i,1,m)
		{
			y=t.substr(i);
			z=t.substr(0,m-i-1);
			if(y==z)
			{
				I=i;
				break;
			}
		}
		if(I==-1)
		{
			while(a[0]!=0 && a[1]!=0)
			{
				if(a[0]-b[0]>=0 && a[1]-b[1]>=0)
				{
					x+=t;
					a[0]-=b[0];a[1]-=b[1];
				}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='1';
					a[0]=0;a[1]=0;
				}
			}
		}
		else
		{
			ll x0=0;ll x1=0;
			rep(i,0,I)
			{
				if(t[0]=='0')
				x0++;
				else
				x1++;
			}
			string ss=t.substr(0,I-1);
			a[0]-=b[0];a[1]-=b[1];
			x+=t;
			while(a[0]!=0 && b[0]!=0)
			{
				if(a[0]-x0>=0 && a[1]-x1>=0)
				{
					x+=ss;
					a[0]-=x0;a[1]-=x1;
				}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='1';
					a[0]=0;a[1]=0;
				}
			}
		}
		cout<<x;
	}
	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;
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;
		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;
}


#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;
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;
		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)
				{
					cout<<ss;
					a[0]-=x0;a[1]-=x1;
		    	}
				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;
			}
		}
	}
	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;
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;
		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 && x0!=0 && x1!=0)
				{
			//		cout<<ss;
			//		a[0]-=x0;a[1]-=x1;
					rep(i,0,(a[0]+a[1])/(x0+x1))
					cout<<ss;
					a[0]/=x0;a[1]/=x1;
		    	}
				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;
			}
		}
	}
	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;
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;
		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=-1;
		rep(i,1,m)
		{
			y=t.substr(i);
			z=t.substr(0,m-i-1);
			if(y==z)
			{
				I=i;
				break;
			}
		}
		if(I==-1)
		{
			while(a[0]!=0 || a[1]!=0)
			{
				if(a[0]-b[0]>=0 && a[1]-b[1]>=0)
				{
					x+=t;
					a[0]-=b[0];a[1]-=b[1];
				}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='1';
					a[0]=0;a[1]=0;
				}
			}
		}
		else
		{
			ll x0=0;ll x1=0;
			rep(i,0,I)
			{
				if(t[0]=='0')
				x0++;
				else
				x1++;
			}
			string ss=t.substr(0,I-1);
			a[0]-=b[0];a[1]-=b[1];
			x+=t;
			while(a[0]!=0 || b[0]!=0)
			{
				if(a[0]-x0>=0 && a[1]-x1>=0)
				{
					x+=ss;
					a[0]-=x0;a[1]-=x1;
				}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='1';
					a[0]=0;a[1]=0;
				}
			}
		}
		cout<<x;
	}
	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;
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;
		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)
				{
					x+=t;
					a[0]-=b[0];a[1]-=b[1];
				}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='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];
			x+=t;
			while(true)
			{
				if(a[0]-x0>=0 && a[1]-x1>=0)
				{
					x+=ss;
					a[0]-=x0;a[1]-=x1;
		    	}
				else
				{
					rep(i,0,a[0])
					x+='0';
					rep(i,0,a[1])
					x+='1';
					a[0]=0;a[1]=0;
				}
				if(a[0]==0 && a[1]==0)
				break;
			}
		}
		cout<<x;
	}
	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 N         500005
#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 pdp[N],modi[N];
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;
		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;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define ll long long int
map<int,int> mp;
int main(){
 IOS
 string s,t;
 ll on=0,ze=0,onn=0,zee=0,ans=0;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='1')
  	 on++;
  	 else
  	 ze++;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]=='1')
  	onn++;
  	else
  	zee++;
  }
  if((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  int i,j,k,f,b=0,n=t.size();
 int L = 0, R = 0;
 int z[n];
for (int i = 1; i < t.size(); i++) {
  if (i > R) {
    L = R = i;
    while (R < n && t[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 < n && t[R-L] == t[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
 for(int i=1;i<n;i++)
  {
  	if(z[i]+i==t.size()){
  		k=i;
  		b=1;
  		break;

	  }
  }
  if(b==1){
  for(int i=0;i<ans;i++)
   cout<<t;
   int u=k;
   //cout<<u<<" ";
    while(on!=0||ze!=0){
    	//cout<<t[u]<<" "
    	if(ze>0&&t[u]=='0'){
    		cout<<'0';
    		ze--;
		}
		else if(on>0&&t[u]=='1'){
			cout<<'1';
			on--;
		}
		else
		{
			if(ze>0)
			{ cout<<'0';
			   ze--;}
			   else{
			   	cout<<'1';
			   	on--;
			   }
		}
		u++;
		if(u==t.size())
		  u=k;

	}
   }
   else{
   	while((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  for(int i=0;i<ans;i++)
   cout<<t;
   for(int i=0;i<on;i++)
    cout<<'1';
    for(int i=0;i<ze;i++)
    cout<<'0';
   }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define ll long long int
map<int,int> mp;
int main(){
 IOS
 string s,t,u;
 ll on=0,ze=0,onn=0,zee=0,ans=0;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='1')
  	 on++;
  	 else
  	 ze++;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]=='1')
  	onn++;
  	else
  	zee++;
  }
  while((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  for(int i=0;i<ans;i++)
   cout<<t;
   for(int i=0;i<on;i++)
    cout<<'1';
    for(int i=0;i<ze;i++)
    cout<<'0';

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define ll long long int
map<int,int> mp;
int main(){
 IOS
 string s,t;
 ll on=0,ze=0,onn=0,zee=0,ans=0;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='1')
  	 on++;
  	 else
  	 ze++;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]=='1')
  	onn++;
  	else
  	zee++;
  }
  if((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  int i,j,k,f,b=0,n=t.size();
 int L = 0, R = 0;
 int z[n];
for (int i = 1; i < t.size(); i++) {
  if (i > R) {
    L = R = i;
    while (R < n && t[R-L] == t[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 < n && t[R-L] == t[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
 for(int i=1;i<n;i++)
  { //cout<<z[i]<<" ";
  	if(z[i]+i==t.size()){
  		k=i;
  		b=1;
  		break;

	  }
  }
  if(b==1){
  for(int i=0;i<ans;i++)
   cout<<t;
   int u=k;
   //cout<<u<<" ";
    while(on!=0||ze!=0){
    	//cout<<t[u]<<" "
    	if(ze>0&&t[u]=='0'){
    		cout<<'0';
    		ze--;
		}
		else if(on>0&&t[u]=='1'){
			cout<<'1';
			on--;
		}
		else
		{
			if(ze>0)
			{ cout<<'0';
			   ze--;}
			   else{
			   	cout<<'1';
			   	on--;
			   }
		}
		u++;
		if(u==t.size())
		  u=k;

	}
   }
   else{
   	while((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  for(int i=0;i<ans;i++)
   cout<<t;
   for(int i=0;i<on;i++)
    cout<<'1';
    for(int i=0;i<ze;i++)
    cout<<'0';
   }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define ll long long int
map<int,int> mp;
int main(){
 IOS
 string s,t;
 ll on=0,ze=0,onn=0,zee=0,ans=0;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='1')
  	 on++;
  	 else
  	 ze++;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]=='1')
  	onn++;
  	else
  	zee++;
  }
  if((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  int i,j,k,f,b=0,n=t.size();
 int L = 0, R = 0;
 int z[n];
for (int i = 1; i < t.size(); i++) {
  if (i > R) {
    L = R = i;
    while (R < n && t[R-L] == t[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 < n && t[R-L] == t[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
 for(int i=1;i<n;i++)
  { //cout<<z[i]<<" ";
  	if(z[i]+i==t.size()){
  		k=i;
  		b=1;
  		break;

	  }
  }
  //cout<<"b"<<b<<" ";
  if(b==1){
  for(int i=0;i<ans;i++)
   cout<<t;
   int u=z[k];
   //cout<<u<<" ";
   u=u%n;
    while(on!=0||ze!=0){
    	//cout<<t[u]<<" "
    	if(ze>0&&t[u]=='0'){
    		cout<<'0';
    		ze--;
		}
		else if(on>0&&t[u]=='1'){
			cout<<'1';
			on--;
		}
		else
		{
			if(ze>0)
			{ cout<<'0';
			   ze--;}
			   else{
			   	cout<<'1';
			   	on--;
			   }
		}
		u++;
		if(u==t.size())
		  u=z[k];

	}
   }
   else{
   	while((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  for(int i=0;i<ans;i++)
   cout<<t;
   for(int i=0;i<on;i++)
    cout<<'1';
    for(int i=0;i<ze;i++)
    cout<<'0';
   }

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define ll long long int
map<int,int> mp;
int main(){
 IOS
 string s,t;
 ll on=0,ze=0,onn=0,zee=0,ans=0;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
  	if(s[i]=='1')
  	 on++;
  	 else
  	 ze++;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]=='1')
  	onn++;
  	else
  	zee++;
  }
  if((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  int i,j,k,f,b=0;
  for( i=1;i<t.size();i++){
  	if(t[i]==t[0]){
  		j=i+1,k=1,f=0;
  		while(j!=t.size()){
  			if(t[j]!=t[k]){
  				f=1;
  				break;
			  }
			  j++,k++;
		  }
		  if(f==0){
		  	b=1;
		  	break;
		  }
	  }
  }
  if(b==1){
  for(int i=0;i<ans;i++)
   cout<<t;
   int u=k;
   //cout<<u<<" ";
    while(on!=0||ze!=0){
    	//cout<<t[u]<<" "
    	if(ze>0&&t[u]=='0'){
    		cout<<'0';
    		ze--;
		}
		else if(on>0&&t[u]=='1'){
			cout<<'1';
			on--;
		}
		else
		{
			if(ze>0)
			{ cout<<'0';
			   ze--;}
			   else{
			   	cout<<'1';
			   	on--;
			   }
		}
		u++;
		if(u==t.size())
		  u=k;

	}
   }
   else{
   	while((onn+zee)<=(on+ze)&&onn<=on&&zee<=ze){
  	on-=onn;
  	ze-=zee;
  	ans++;
  }
  for(int i=0;i<ans;i++)
   cout<<t;
   for(int i=0;i<on;i++)
    cout<<'1';
    for(int i=0;i<ze;i++)
    cout<<'0';
   }

return 0;
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e15 + 7, p = 7;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 51)%mod;
            h = h + (s[i] - '0' + 1);
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] - '0' + 1) * P[i];
            if(mp[h])
                ptr = i + 1;
        }
        //cout << ptr << "\n";
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e16 + 7, p = 17;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 51)%mod;
            h = h + (s[i] + 1);
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] + 1) * P[i];
            if(mp[h])
                ptr = i + 1;
        }
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e15 + 7, p = 31;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 31)%mod;
            h = (h + (s[i] - '0' + 1))%mod;
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = (h + ((s[i] - '0' + 1) * P[i])%mod)%mod;
            if(mp[h])
                ptr = i + 1;
        }
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e9 + 7, p = 11;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 11)%mod;
            h = h + (s[i] - '0' + 1);
            //cout << h << " ";
            mp[h] = i;
        }
        //cout << "\n";
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] - '0' + 1) * P[i];
            //cout << h << " ";
            if(mp[h])
                ptr = i + 1;
        }
        //cout << "\n";
        //cout << ptr << "**\n";
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e15 + 7, p = 7;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 7)%mod;
            h = h + (s[i] - '0' + 1);
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] - '0' + 1) * P[i];
            if(mp[h])
                ptr = i + 1;
        }
        //cout << ptr << "\n";
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e9 + 7, p = 11;

int longestPrefixSuffix(string s)
{
    int n = s.length();
        int arr[n];
        arr[0] = 0;
        int len = 0;
        for(int i = 1;i<n;){
            if(s[len]==s[i]){
                len++;
                arr[i++] = len;
            }
            else{
                if(len!=0){
                    len = arr[len-1];
                }
                else{
                    arr[i] = 0;
                    i++;
                }
            }
        }
        return arr[n-1];
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        ptr = longestPrefixSuffix(s);
        if(ptr == l2)
            l2--;
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e9 + 7, p = 11;

int lps(string &s, int l){
    int arr[l + 5] = {};
    arr[0] = 0;
    for(int i = 1; i < l; i++){
        if(s[i] == s[arr[i - 1]])
            arr[i] = arr[i - 1] + 1;
        else
            arr[i] = 0;
    }
    return arr[l - 1];
}

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string s, t;
        cin >> s >> t;
        int l1 = s.length(), l2 = t.length();
        int ptr = lps(t, l2);
        int j = 0, one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(s[i] == '0')
                zero++;
            else
                one++;
        }
        string ans = {};
        while(zero > 0 && one > 0){
            if(t[j] == '0'){
                ans.PB('0');
                zero--;
            }
            else{
                ans.PB('1');
                one--;
            }
            j++;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        for(int i = 0; i < one; i++)
            ans.PB('1');
        cout << ans;
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e15 + 7, p = 51;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 51)%mod;
            h = h + (s[i] - '0' + 1);
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] - '0' + 1) * P[i];
            if(mp[h])
                ptr = i + 1;
        }
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e15 + 7, p = 2;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 2)%mod;
            h = (h + (s[i] - '0' + 1))%mod;
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = (h + ((s[i] - '0' + 1) * P[i])%mod)%mod;
            if(mp[h])
                ptr = i + 1;
        }
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


// keep trying :)
#include <bits/stdc++.h>
#define float long double
#define int long long
#define ll long long
#define PB push_back
#define MP make_pair
#define ss second
#define ff first
#define PI 3.14159265
#define MXX 9*(1e18)
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
void PT(int a);
void PT1(int a);
const int M = 6*1e5 + 7, mod = 1e16 + 7, p = 2;
int P[M];

void precompute(){
    P[0] = 1;
    for(int i = 1; i < M; i++){
        P[i] = (P[i - 1] * p)%mod;
    }
}

map <int, int> mp;

signed main(){
    fastrack;
    //int tt; cin >> tt; while(tt--)
    {
        string t, s;
        cin >> t >> s;
        int l1 = t.length(), l2 = s.length(), h = 0, ptr = 0;
        precompute();
        for(int i = l2 - 1; i >= 0; i--){
            h = (h * 2)%mod;
            h = h + (s[i] + 1);
            mp[h] = i;
        }
        h = 0;
        for(int i = 0; i < l2 - 1; i++){
            h = h + (s[i] + 1) * P[i];
            if(mp[h])
                ptr = i + 1;
        }
        int one = 0, zero = 0;
        for(int i = 0; i < l1; i++){
            if(t[i] == '1')
                one++;
            else
                zero++;
        }
        string ans = "";
        int j = 0;
        while(1){
            if(s[j] == '1' && one > 0){
                ans.PB('1');
                j++;
                one--;
            }
            else if(s[j] == '1' && one == 0)
                break;
            if(s[j] == '0' && zero > 0){
                ans.PB('0');
                j++;
                zero--;
            }
            else if(s[j] == '0' && zero == 0)
                break;
            if(j == l2)
                j = ptr;
        }
        for(int i = 0; i < one; i++)
            ans.PB('1');
        for(int i = 0; i < zero; i++)
            ans.PB('0');
        cout << ans << "\n";
    }
    return 0;
}

void PT(int a){
    cout << a << "\n";
}

void PT1(int a){
    cout << a << " ";
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int n = (int)t.size();
    vector<int> pr(n);
    for (int i = 0; i < n - 1; ++i){
        int j = pr[i];
        while (j > 0 && t[j] != t[i + 1]){
            j = pr[j - 1];
        }
        if (t[j] == t[i + 1]){
            pr[i + 1] = j + 1;
        }
        else{
            pr[i + 1] = j;
        }
    }
    int d = pr[n - 1];
    if (d == n - 1)
    {
        if (t[0] == '1')
        {
            for (int i = 0; i < a; ++i)
            {
                cout << '1';
            }
            for (int i = 0; i < b; ++i)
            {
                cout << '0';
            }
        }
        else
        {
            for (int i = 0; i < b; ++i)
            {
                cout << '0';
            }
            for (int i = 0; i < a; ++i)
            {
                cout << '1';
            }
        }
        return 0;
    }
    if (d == 0)
    {
        d = n;
    }
    int res = inf;
    if (ta > 0)
    {
        res = min(res, a / ta);
    }
    if (tb > 0)
    {
        res = min(res, b / tb);
    }
    if (res)
    {
        cout << t;
        a -= ta;
        b -= tb;
    }
    string td;
    int tan = 0, tbn = 0;
    for (int i = n - d - 1; i < n; ++i)
    {
        td.pb(t[i]);
        if (t[i] == '1')
        {
            ++tan;
        }
        else
        {
            ++tbn;
        }
    }
    while (a >= tan && b >= tbn)
    {
        cout << td;
        a -= tan;
        b -= tbn;
    }
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int n = (int)t.size();
    vector<int> pr(n);
    for (int i = 0; i < n - 1; ++i){
        int j = pr[i];
        while (j > 0 && t[j] != t[i + 1]){
            j = pr[j - 1];
        }
        if (t[j] == t[i + 1]){
            pr[i + 1] = j + 1;
        }
        else{
            pr[i + 1] = j;
        }
    }
    int d = pr[n - 1];
    if (d == n - 1)
    {
        if (t[0] == '1')
        {
            for (int i = 0; i < a; ++i)
            {
                cout << '1';
            }
            for (int i = 0; i < b; ++i)
            {
                cout << '0';
            }
        }
        else
        {
            for (int i = 0; i < b; ++i)
            {
                cout << '0';
            }
            for (int i = 0; i < a; ++i)
            {
                cout << '1';
            }
        }
        return 0;
    }
    int res = inf;
    if (ta > 0)
    {
        res = min(res, a / ta);
    }
    if (tb > 0)
    {
        res = min(res, b / tb);
    }
    string ans, pans;
    if (res)
    {
        ans += t;
        a -= ta;
        b -= tb;
        string td;
        int tan = 0, tbn = 0;
        for (int i = d; i < n; ++i)
        {
            td.pb(t[i]);
            if (t[i] == '1')
            {
                ++tan;
            }
            else
            {
                ++tbn;
            }
        }
        while (a >= tan && b >= tbn)
        {
            ans += td;
            a -= tan;
            b -= tbn;
        }
        /*
        int tac = 0, tbc = 0;
        string tp;
        for (int i = 0; i < n - d; ++i)
        {
            tp.pb(t[i]);
            if (t[i] == '1')
            {
                tac++;
            }
            else
            {
                tbc++;
            }
        }
        while (a >= tac && b >= tbc && d != n)
        {
            a -= tac;
            b -= tbc;
            pans += tp;
        }
        */
    }
    cout << ans;
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int n = (int)t.size();
    vector<int> pr(n);
    for (int i = 0; i < n - 1; ++i){
        int j = pr[i];
        while (j > 0 && t[j] != t[i + 1]){
            j = pr[j - 1];
        }
        if (t[j] == t[i + 1]){
            pr[i + 1] = j + 1;
        }
        else{
            pr[i + 1] = j;
        }
    }
    int d = pr[n - 1];
    if (d == 0)
    {
        d = n;
    }
    int res = inf;
    if (ta > 0)
    {
        res = min(res, a / ta);
    }
    if (tb > 0)
    {
        res = min(res, b / tb);
    }
    if (res)
    {
        cout << t;
        a -= ta;
        b -= tb;
    }
    string td;
    int tan = 0, tbn = 0;
    for (int i = n - d - 1; i < n; ++i)
    {
        td.pb(t[i]);
        if (t[i] == '1')
        {
            ++tan;
        }
        else
        {
            ++tbn;
        }
    }
    while (a >= tan && b >= tbn)
    {
        cout << td;
        a -= tan;
        b -= tbn;
    }
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int res = inf;
    if (ta > 0)
    {
        res = min(res, a / ta);
    }
    if (tb > 0)
    {
        res = min(res, b / tb);
    }
    a -= res * ta;
    b -= res * tb;
    for (int i = 0; i < res; ++i)
    {
        cout << t;
    }
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int n = (int)t.size();
    vector<int> pr(n);
    for (int i = 0; i < n - 1; ++i){
        int j = pr[i];
        while (j > 0 && t[j] != t[i + 1]){
            j = pr[j - 1];
        }
        if (t[j] == t[i + 1]){
            pr[i + 1] = j + 1;
        }
        else{
            pr[i + 1] = j;
        }
    }
    int d = pr[n - 1];
    int res = inf;
    if (ta > 0)
    {
        res = min(res, a / ta);
    }
    if (tb > 0)
    {
        res = min(res, b / tb);
    }
    if (res)
    {
        cout << t;
        a -= ta;
        b -= tb;
    }
    string td;
    int tan = 0, tbn = 0;
    for (int i = n - d - 1; i < n; ++i)
    {
        td.pb(t[i]);
        if (t[i] == '1')
        {
            ++tan;
        }
        else
        {
            ++tbn;
        }
    }
    while (a >= tan && b >= tbn)
    {
        cout << td;
        a -= tan;
        b -= tbn;
    }
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<int> v(n), p1(n, 0), p2(n, 0), s1(n, 0), s2(n, 0);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    if (v[0] == 1)
    {
        p1[0] = 1;
    }
    if (v[0] == 2)
    {
        p2[0] = 1;
    }
    for (int i = 1; i < n; ++i)
    {
        p1[i] = p1[i - 1];
        p2[i] = p2[i - 1];
        if (v[i] == 1)
        {
            p1[i]++;
            p2[i] = 0;
        }
        if (v[i] == 2)
        {
            p2[i]++;
            p1[i] = 0;
        }
    }
    if (v[n - 1] == 1)
    {
        s1[n - 1] = 1;
    }
    if (v[n - 1] == 2)
    {
        s2[n - 1] = 1;
    }
    for (int i = n - 2; i >= 0; --i)
    {
        s1[i] = s1[i + 1];
        s2[i] = s2[i + 1];
        if (v[i] == 1)
        {
            s1[i]++;
            s2[i] = 0;
        }
        if (v[i] == 2)
        {
            s2[i]++;
            s1[i] = 0;
        }
    }
    int ans = 0;
    for (int i = 1; i < n; ++i)
    {
        ans = max(ans, 2 * max(min(p1[i - 1], s2[i]), min(p2[i - 1], s1[i])));
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

const int inf = 1e18;
const double eps = 1e-6;

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s, t;
    cin >> s >> t;
    int a = 0, b = 0, ta = 0, tb = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            ++a;
        }
        else
        {
            ++b;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            ++ta;
        }
        else
        {
            ++tb;
        }
    }
    int res = min(a / ta, b / tb);
    a -= res * ta;
    b -= res * tb;
    for (int i = 0; i < res; ++i)
    {
        cout << t;
    }
    for (int i = 0; i < a; ++i)
    {
        cout << '1';
    }
    for (int i = 0; i < b; ++i)
    {
        cout << '0';
    }
    return 0;
}


#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
vector<int> z_function_trivial(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1; i < n; ++i)
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
    return z;
}int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   string s,t;
   cin>>s>>t;
   vector<int>z=z_function_trivial(t);
   //for(auto x: z)
   //	cout<<x<<' ';
   int a=0,b=0,ta=0,tb=0;
   for(int i=0;i<s.size();i++)
   {
   	if(s[i]=='0')
   		a++;
   	else
   		b++;
   }
   for(int i=0;i<t.size();i++)
   {
   	if(t[i]=='0')
   		ta++;
   	else
   		tb++;
   }
   if(s.size()<t.size())
   {
   	cout<<s<<endl;
   	return 0;
   }
   if(ta>a||tb>b)
   {
   	cout<<s<<endl;
   	return 0;
   }
   string ans(t);
   a-=ta,b-=tb;
   int m=0,d=t.size();
   for(int i=0;i<t.size();i++)
   {
   	int x=z[i];
   	if(t.size()-i==x&&m<x)
   	{
   		m=x;
   		d=i;
   	}
   }
   string ad;
   ///cout<<m<<endl;
   for(int i=m;i<t.size();i++)
   {
   	ad.pb(t[i]);
   }
  // cout<<ad<<endl;
   for(int i=0;i<m;i++)
   {
   	if(t[i]=='0')
   		ta--;
   	else
   		tb--;
   }
   while(a>0&&b>0&&ta<=a&&tb<=b)
   {
   	ans=ans+ad;
   	a-=ta,b-=tb;
   }
   while(a>0)
   {
   	ans.pb('0');
   	a--;
   }
   while(b>0)
   {
   	ans.pb('1');
   	b--;
   }
   cout<<ans<<endl;
}


#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 998244353
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   string s,t;
   cin>>s>>t;
   vector<int>z=z_function(t);
   //for(auto x: z)
   //	cout<<x<<' ';
   int a=0,b=0,ta=0,tb=0;
   for(int i=0;i<s.size();i++)
   {
   	if(s[i]=='0')
   		a++;
   	else
   		b++;
   }
   for(int i=0;i<t.size();i++)
   {
   	if(t[i]=='0')
   		ta++;
   	else
   		tb++;
   }
   if(s.size()<t.size())
   {
   	cout<<s<<endl;
   	return 0;
   }
   if(ta>a||tb>b)
   {
   	cout<<s<<endl;
   	return 0;
   }
   string ans(t);
   a-=ta,b-=tb;
   int m=0,d=t.size();
   for(int i=0;i<t.size();i++)
   {
   	int x=z[i];
   	if(t.size()-i==x&&m<x)
   	{
   		m=x;
   		d=i;
   	}
   }
   string ad;
   ///cout<<m<<endl;
   for(int i=m;i<t.size();i++)
   {
   	ad.pb(t[i]);
   }
  // cout<<ad<<endl;
   for(int i=0;i<m;i++)
   {
   	if(t[i]=='0')
   		ta--;
   	else
   		tb--;
   }
   while(ta<=a&&tb<=b)
   {
   	ans=ans+ad;
   	a-=ta,b-=tb;
   }
   while(a)
   {
   	ans.pb('0');
   	a--;
   }
   while(b)
   {
   	ans.pb('1');
   	b--;
   }
   cout<<ans<<endl;
}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    bool flag=0; for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    // for(auto ind : g[cur]) printf("%d ", ind); printf("\n");
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

}

void reinit() {
    cont=contt;
    for(int i=1; i<=m; i++) p[i]=pp[i];
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(raiz==0) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    reinit(); for(int i=1; i<=n; i++) if(marc[i]!=1) dfs(i, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    reinit(); dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

    bool flag=0;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(!raiz) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    cont=contt; dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }
    cont=contt; dfs(raiz3, 3);
    if(cont==0) { printf("YES\n"); return 0; }
    for(int i=1; i<=100; i++) {
        contt=cont;
        dfs(rand()%n+1, i+3);
        if(cont==0) { printf("YES\n"); return 0; }
    }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;

void dfs(int cur, int k) {
    marc[cur]=k;
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(k==2) p[pes]^=1;
        if(marc[viz]) continue;
        if(k==2) {

            if(p[pes]) dfs(viz, k);
            else dfs(viz, k^1);
        }
        else {
            if(p[pes]) dfs(viz, k);
            else dfs(viz, k^1);
        }
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    memset(marc, -1, sizeof(marc));
    for(int i=1; i<=n; i++) if(marc[i]<0) dfs(i, 1);
    cont=0; for(int i=1; i<=m; i++) cont+=p[i];

    if(cont==0||cont==m) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    bool flag=0; for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    for(auto ind : g[cur]) printf("%d ", ind); printf("\n");
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            printf("switch %d\n", ind);
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

}

void reinit() {
    cont=contt;
    for(int i=1; i<=m; i++) p[i]=pp[i];
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(raiz==0) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    reinit(); for(int i=1; i<=n; i++) if(marc[i]!=1) dfs(i, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    reinit(); dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

    bool flag=0;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

}

void reinit() {
    cont=contt;
    for(int i=1; i<=m; i++) p[i]=pp[i];
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(!raiz) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    reinit(); dfs(raiz, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    reinit(); dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }
    reinit(); dfs(raiz3, 3);
    if(cont==0) { printf("YES\n"); return 0; }
    for(int i=1; i<=100; i++) {
        reinit();
        dfs(rand()%n+1, i+3);
        if(cont==0) { printf("YES\n"); return 0; }
    }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;

void dfs(int cur, int k) {
    marc[cur]=k; printf("%d> %d\n", cur, k);
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(k==2) p[pes]^=1;
        if(marc[viz]) continue;
        if(k==2) {

            if(p[pes]) dfs(viz, k);
            else dfs(viz, ((k-1)^1)+1);
        }
        else {
            if(p[pes]) dfs(viz, k);
            else dfs(viz, ((k-1)^1)+1);
        }
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }

    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    for(int i=1; i<=n; i++) if(!marc[i]) dfs(i, 1);
    cont=0;
    for(int i=1; i<=m; i++) cont+=p[i];

    if(cont==0||cont==m) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, raiz;

void dfs(int cur) {
    bool flag=0; marc[cur]=1;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]) continue;
        dfs(viz);
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++; raiz=a;
        }
        g[a].push_back(b); g[b].push_back(a);
    }

    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz);

    if(cont) printf("NO\n");
    else printf("YES\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, raiz, raiz2;

void dfs(int cur, int k) {
    marc[cur]=k;

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

    bool flag=0;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++; raiz=a; raiz2=b;
        }
        g[a].push_back(b); g[b].push_back(a);
    }

    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;

void dfs(int cur, int k) {
    marc[cur]=k; //printf("%d> %d\n", cur, k);
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(k==2) p[pes]^=1;
        if(marc[viz]) continue;
        if(k==2) {

            if(p[pes]) dfs(viz, k);
            else dfs(viz, ((k-1)^1)+1);
        }
        else {
            if(p[pes]) dfs(viz, k);
            else dfs(viz, ((k-1)^1)+1);
        }
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }

    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    for(int i=1; i<=n; i++) if(!marc[i]) dfs(i, 1);
    cont=0;
    for(int i=1; i<=m; i++) cont+=p[i];

    if(cont==0||cont==m) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    bool flag=0; for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    // for(auto ind : g[cur]) printf("%d ", ind); printf("\n");
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

}

void reinit() {
    cont=contt;
    for(int i=1; i<=m; i++) p[i]=pp[i];
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(raiz==0) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    reinit(); for(int i=1; i<=n; i++) if(marc[i]!=1) dfs(i, 1);
    if(cont==0||cont==m) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;

void dfs(int cur, int k) {
    marc[cur]=k;
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(k) p[pes]^=1;
        if(marc[viz]) continue;
        if(k) {

            if(p[pes]) dfs(viz, k);
            else dfs(viz, k^1);
        }
        else {
            if(p[pes]) dfs(viz, k);
            else dfs(viz, k^1);
        }
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    memset(marc, -1, sizeof(marc));
    for(int i=1; i<=n; i++) if(marc[i]<0) dfs(i, 0);
    cont=0; for(int i=1; i<=m; i++) cont+=p[i];

    if(cont==0||cont==m) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, contt, raiz, raiz2, raiz3;

void dfs(int cur, int k) {
    marc[cur]=k;

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

    bool flag=0;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++;
            if(!raiz) { raiz=a; raiz2=b; }
            else raiz3=a;
        }
        g[a].push_back(b); g[b].push_back(a);
    }
    contt=cont;
    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    cont=contt; dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }
    cont=contt; dfs(raiz3, 3);
    if(cont==0) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;
bool erro=0;

void dfs(int cur, int k) {
    marc[cur]=k; //printf("%d %d\n", cur, k);
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(marc[viz]>=0&&p[pes]&&marc[cur]!=marc[viz]) erro=1;
        if(marc[viz]>=0&&p[pes]==0&&marc[cur]==marc[viz]) erro=1;
        if(marc[viz]>=0) continue;

        if(p[pes]) dfs(viz, k);
        else dfs(viz, k^1);
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }

    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    memset(marc, -1, sizeof(marc));
    for(int i=1; i<=n; i++) if(marc[i]<0) dfs(i, 0);

    if(!erro) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont;

void dfs(int cur, int k) {
    marc[cur]=k;
    for(int i=0; i<g[cur].size(); i++) {
        int viz=g[cur][i]; int pes=gg[cur][i];
        if(k==2) p[pes]^=1;
        if(marc[viz]) continue;
        if(k==2) {

            if(p[pes]) dfs(viz, k);
            else dfs(viz, (k^1);
        }
        else {
            if(p[pes]) dfs(viz, k);
            else dfs(viz, (k^1);
        }
    }
}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        while(c--) {
            int a; scanf("%d", &a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        gg[a].push_back(i); gg[b].push_back(i);
        g[a].push_back(b); g[b].push_back(a);
    }

    memset(marc, -1, sizeof(marc));
    for(int i=1; i<=n; i++) if(marc[i]<0) dfs(i, 1);
    cont=0; for(int i=1; i<=m; i++) cont+=p[i];

    if(cont==0||cont==m) printf("YES\n");
    else printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], pp[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, raiz, raiz2;

void dfs(int cur, int k) {
    bool flag=0; marc[cur]=k;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]==k) continue;
        dfs(viz, k);
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        pp[i]=p[i];
        if(!p[i]) {
            cont++; raiz=a; raiz2=b;
        }
        g[a].push_back(b); g[b].push_back(a);
    }

    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz, 1);
    if(cont==0) { printf("YES\n"); return 0; }
    dfs(raiz2, 2);
    if(cont==0) { printf("YES\n"); return 0; }

    printf("NO\n");

}


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

const int MAXN=1e5+5;
vector<int> g[MAXN], gg[MAXN];
int p[MAXN], v[MAXN][2];
int marc[MAXN];
int n, m, cont, raiz;

void dfs(int cur) {
    bool flag=0; marc[cur]=1;
    for(auto ind : gg[cur]) if(!p[ind]) flag=1;
    if(flag) {
        for(auto ind : gg[cur]) {
            if(p[ind]) cont++;
            else cont--;
            p[ind]^=1;
        }
    }

    for(auto viz : g[cur]) {
        if(marc[viz]) continue;
        dfs(viz);
    }

}

int main() {
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++) scanf("%d", &p[i]);
    for(int i=1; i<=n; i++) {
        int c; scanf("%d", &c);
        for(int j=0; j<c; j++) {
            int a; scanf("%d", &a);
            gg[i].push_back(a);
            if(v[a][0]) v[a][1]=i;
            else v[a][0]=i;
        }
    }

    cont=0;
    for(int i=1; i<=m; i++) {
        int a=v[i][0]; int b=v[i][1];
        if(!p[i]) {
            cont++; raiz=a;
        }
        g[a].push_back(b); g[b].push_back(a);
    }

    if(cont==0) { printf("YES\n"); return 0; }

    dfs(raiz);
    // for(int i=1; i<=m; i++) printf("%d ", p[i]); printf("\n");

    for(int i=1; i<=m; i++) {
        if(!p[i]) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");

}


#include <cstdio>
#include <algorithm>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;

int st[nmax + 1];
bool ans = 1;
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< pair<int, int> > g[nmax + 1];

void dfs (int nod) {
    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == -1) {
            viz[ i.first ] = viz[ nod ] ^ i.second;
            dfs( i.first );
        } else if (viz[ i.first ] != (viz[ nod ] ^ i.second)) {
            ans = 0;
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        int c = 1 - st[ i ];
        g[ b[ i ][ 0 ] ].push_back(make_pair(b[ i ][ 1 ], c));
        g[ b[ i ][ 1 ] ].push_back(make_pair(b[ i ][ 0 ], c));

        viz[ i ] = -1;
    }

    ans = 1;
    for (int i = 1; i <= n; ++ i) {
        if (viz[ i ] == -1) {
            viz[ i ] = 1;
            dfs( i );
        }
    }

    int sum = 0;
    for (int i = 1; i <= n; ++ i) {
        sum += (st[ i ] == 1);
    }
    if (sum == n && ans == 0) {
        exit( 0 );
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;

int st[nmax + 1];
bool ans = 1;
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< pair<int, int> > g[nmax + 1];

void dfs (int nod) {
    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == -1) {
            viz[ i.first ] = viz[ nod ] ^ i.second;
            dfs( i.first );
        } else if (viz[ i.first ] != (viz[ nod ] ^ i.second)) {
            ans = 0;
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        int c = 1 - st[ i ];
        g[ b[ i ][ 0 ] ].push_back(make_pair(b[ i ][ 1 ], c));
        g[ b[ i ][ 1 ] ].push_back(make_pair(b[ i ][ 0 ], c));

        viz[ i ] = -1;
    }

    ans = 1;
    for (int i = 1; i <= n; ++ i) {
        if (viz[ i ] == -1) {
            viz[ i ] = 1;
            dfs( i );
        }
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;

int st[nmax + 1];
bool ans = 1;
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< pair<int, int> > g[nmax + 1];

void dfs (int nod) {
    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == -1) {
            viz[ i.first ] = viz[ nod ] ^ i.second;
            dfs( i.first );
        } else if (viz[ i.first ] != (viz[ nod ] ^ i.second)) {
            ans = 0;
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    int sum = 0;
    for (int i = 1; i <= n; ++ i) {
        sum += (st[ i ] == 1);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        int c = 1 - st[ i ];
        if (sum == n && c == 1) exit(-1);
        g[ b[ i ][ 0 ] ].push_back(make_pair(b[ i ][ 1 ], c));
        g[ b[ i ][ 1 ] ].push_back(make_pair(b[ i ][ 0 ], c));

        if (b[ i ].size() != 2) exit(0);

        viz[ i ] = -1;
    }

    ans = 1;
    for (int i = 1; i <= n; ++ i) {
        if (viz[ i ] == -1) {
            viz[ i ] = 1;
            dfs( i );
        }
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;

int st[nmax + 1];
bool ans = 1;
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< pair<int, int> > g[nmax + 1];

void dfs (int nod) {
    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == -1) {
            viz[ i.first ] = viz[ nod ] ^ i.second;
            dfs( i.first );
        } else if (viz[ i.first ] != (viz[ nod ] ^ i.second)) {
            ans = 0;
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        int c = 1 - st[ i ];
        g[ b[ i ][ 0 ] ].push_back(make_pair(b[ i ][ 1 ], c));
        g[ b[ i ][ 1 ] ].push_back(make_pair(b[ i ][ 0 ], c));

        viz[ i ] = -1;
    }

    ans = 1;
    for (int i = 1; i <= m; ++ i) {
        if (viz[ i ] == -1) {
            viz[ i ] = 1;
            dfs( i );
        }
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 2e5 + 5;

int nrc, m;
int st[nmax + 1];
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< int > ord;
vector< int > g[nmax + 1][ 2 ];

void dfs (int nod, int ind) {
    if (ind == 1) {
        viz[ nod ] = nrc;
    } else {
        viz[ nod ] = 1;
    }

    for (auto i : g[ nod ][ ind ]) {
        if (viz[ i ] == -1) {
            dfs(i, ind);
        }
    }

    if (ind == 0) {
        ord.push_back( nod );
    }
}

inline void trage_muchie (int x, int y) {
    g[ x ][ 0 ].push_back( y );
    g[ y ][ 1 ].push_back( x );
}

void ctc() {
    memset(viz, -1, sizeof(viz));
    for (int i = 1; i <= 2 * m; ++ i) {
        if (viz[ i ] == -1) {
            dfs(i, 0);
        }
    }

    memset(viz, -1, sizeof(viz));
    nrc = 0;
    for (int i = (int)ord.size() - 1; i >= 0; -- i) {
        if (viz[ ord[ i ] ] == -1) {
            ++ nrc;
            dfs(ord[ i ], 1);
        }
    }
}

int main() {
    int n;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        if (st[ i ] == 0) {
            trage_muchie(b[ i ][ 0 ] + m, b[ i ][ 1 ]);
            trage_muchie(b[ i ][ 0 ], b[ i ][ 1 ] + m);

            trage_muchie(b[ i ][ 1 ] + m, b[ i ][ 0 ]);
            trage_muchie(b[ i ][ 1 ], b[ i ][ 0 ] + m);
        } else {
            trage_muchie(b[ i ][ 0 ], b[ i ][ 1 ]);
            trage_muchie(b[ i ][ 1 ], b[ i ][ 0 ]);

            trage_muchie(b[ i ][ 0 ] + m, b[ i ][ 1 ] + m);
            trage_muchie(b[ i ][ 1 ] + m, b[ i ][ 0 ] + m);
        }
    }

    ctc();

    bool ans = 1;
    for (int i = 1; i <= m; ++ i) {
        if (viz[ i ] == viz[i + m]) ans = 0;
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;

int st[nmax + 1];
bool ans = 1;
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< pair<int, int> > g[nmax + 1];

void dfs (int nod) {
    for (auto i : g[ nod ]) {
        if (viz[ i.first ] == -1) {
            viz[ i.first ] = viz[ nod ] ^ i.second;
            dfs( i.first );
        } else if (viz[ i.first ] != (viz[ nod ] ^ i.second)) {
            ans = 0;
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        int c = 1 - st[ i ];
        g[ b[ i ][ 0 ] ].push_back(make_pair(b[ i ][ 1 ], c));
        g[ b[ i ][ 1 ] ].push_back(make_pair(b[ i ][ 0 ], c));
    }

    memset(viz, -1, sizeof(viz));

    ans = 1;
    for (int i = 1; i <= m; ++ i) {
        if (viz[ i ] == -1) {
            viz[ i ] = 1;
            dfs( i );
        }
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 1e5 + 5;
int st[nmax + 1], ok[nmax + 1];
bool viz[nmax + 1];

int cate = 0;
int r[nmax + 1];
vector< int > g[nmax + 1];

void dfs (int nod) {
    viz[ nod ] = 1;
    cate += (ok[ nod ]);

    for (auto i : g[ nod ]) {
        if (viz[ i ] == 0) {
            dfs ( i );
        }
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        int unu = 0, zero = 0;
        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            if (st[ y ] == 1) unu = 1;
            else zero = 1;

            if (r[ y ] > 0) {
                g[ r[ y ] ].push_back( i );
                g[ i ].push_back( r[ y ] );
            }

            r[ y ] = i;
        }

        if (unu == 1 && zero == 1) {
            ok[ i ] = 1;
        }
    }

    bool ans = 1;
    for (int i = 1; i <= m; ++ i) {
        if (viz[ i ] == 0) {
            cate = 0;
            dfs( i );

            if (cate % 2 == 0) ans = 0;
        }
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

#define fin stdin
#define fout stdout

using namespace std;

//FILE *fin = fopen("x.in", "r"), *fout = fopen("x.out", "w");

typedef long long i64;

const int nmax = 2e5 + 5;

int nrc, m;
int st[nmax + 1];
int viz[nmax + 1];

vector< int > b[nmax + 1];
vector< int > ord;
vector< int > g[nmax + 1][ 2 ];

void dfs (int nod, int ind) {
    if (ind == 1) {
        viz[ nod ] = nrc;
    } else {
        viz[ nod ] = 1;
    }

    for (auto i : g[ nod ][ ind ]) {
        if (viz[ i ] == -1) {
            dfs(i, ind);
        }
    }

    if (ind == 0) {
        ord.push_back( nod );
    }
}

inline void trage_muchie (int x, int y) {
    g[ x ][ 0 ].push_back( y );
    g[ y ][ 1 ].push_back( x );
}

void ctc() {
    memset(viz, -1, sizeof(viz));
    for (int i = 1; i <= 2 * m; ++ i) {
        if (viz[ i ] == -1) {
            dfs(i, 0);
        }
    }

    memset(viz, -1, sizeof(viz));
    nrc = 0;
    for (int i = (int)ord.size() - 1; i >= 0; -- i) {
        if (viz[ ord[ i ] ] == -1) {
            ++ nrc;
            dfs(ord[ i ], 1);
        }
    }
}

int main() {
    int n;
    fscanf(fin, "%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) {
        fscanf(fin, "%d", &st[ i ]);
    }

    for (int i = 1; i <= m; ++ i) {
        int x;
        fscanf(fin, "%d", &x);

        for (int j = 1; j <= x; ++ j) {
            int y;
            fscanf(fin, "%d", &y);
            b[ y ].push_back( i );
        }
    }

    for (int i = 1; i <= n; ++ i) {
        if (st[ i ] == 0) {
            trage_muchie(b[ i ][ 0 ] + m, b[ i ][ 1 ]);
            trage_muchie(b[ i ][ 0 ], b[ i ][ 1 ] + m);

            trage_muchie(b[ i ][ 1 ] + m, b[ i ][ 0 ]);
            trage_muchie(b[ i ][ 1 ], b[ i ][ 0 ] + m);
        } else {
            trage_muchie(b[ i ][ 0 ], b[ i ][ 1 ]);
            trage_muchie(b[ i ][ 1 ], b[ i ][ 0 ]);
        }
    }

    ctc();

    bool ans = 1;
    for (int i = 1; i <= m; ++ i) {
        if (viz[ i ] == viz[i + m]) ans = 0;
    }

    if (ans == 1) fprintf(fout, "YES\n");
    else fprintf(fout, "NO\n");
    return 0;
}