Least common subnumber#5261

Least common subnumber

0.5 seconds
64 megabytes
Hard

A string of digits is a sequence where each character is a digit ranging from to .

A subsequence of such a string is a number that can be formed by removing some (or none) of the characters from the string, without rearranging the remaining characters, and it must not have leading zeros.

A common subsequence between two strings of digits is a number that appears as a subsequence in both strings.

Given two strings of digits, your task is to find the longest common subsequence. If there are multiple subsequences of the same maximum length, select the smallest one in terms of numerical value.

Input

You will be provided with two strings of digits as input. Each string contains up to digits.

Output

Output a single non-negative integer, which is the smallest common subsequence of maximum length from the given strings. If no common subsequence exists, output 0.

Examples

Example 1

Loading
Loading