import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	//auto tokens = split(my_readln());
	//auto N = to!ulong(tokens[0]);
	//auto W = to!ulong(tokens[1]);

	string s = my_readln();
	string t = my_readln();

	int[string] memo;
	uint[][26] dp;

	foreach (i, e; t) dp[e-'a'] ~= cast(uint)i;

	foreach (i; 0..s.length)
	{
		foreach (e; dp[s[i]-'a'])
		{
			if (memo.keys.length == 0)
			{
				memo[[s[i]]] = e;
				break;
			}
			stderr.writeln(memo.keys);
			stderr.writeln(memo.values);
			foreach (key; memo.keys)
			{
				if (memo[key] >= e) continue;

				auto next = key ~ s[i];
				if (e >= memo.get(next, uint.max)) continue;

				memo[next] = e;
			}
		}
	}

	writeln(memo.keys.sort!"a.length > b.length"()[0]);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}