#define loop(i,a,b) for(int i=a; i<b; ++i)
#define min(a,b) (a)<(b)?a:b;
#define max(a,b) (a)>(b)?a:b;
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
char s[100000];
string s1,s2,s3;
int res;

string g( int n )
{
	string res = "{";
	if ( n > 0 )
		res += g( 0 );
	loop(i,1,n)
		res += "," + g( i );
	res += "}";
	return res;
}

vector < string > v;

int main()
{
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);

	gets(s);
	s1 = s;
	gets(s);
	s2 = s;

	int e = -1;
	do
	{
		e++;
		s3 = g(e);
	}
	while ( s1 != s3 );

	res += e;

	e = -1;
	do
	{
		e++;
		s3 = g(e);
	}
	while ( s2 != s3 );

	res += e;


	s1 = g(res);
	printf("%s\n", s1.c_str() );
	return 0;
}