You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 9) — the lengths of the first and the second lists, respectively.

The second line contains *n* distinct digits *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 9) — the elements of the first list.

The third line contains *m* distinct digits *b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ..., *b*<sub class="lower-index">*m*</sub> (1 ≤ *b*<sub class="lower-index">*i*</sub> ≤ 9) — the elements of the second list.
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.

In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.
2 3
4 2
5 7 6
25
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
1
1 1
9
1
19
9 1
5 4 2 3 6 1 7 9 8
9
9
5 3
7 2 5 8 6
3 1 9
12
4 5
5 2 6 4
8 9 1 3 7
12
5 9
4 2 1 6 7
2 3 4 5 6 7 8 9 1
1
9 9
5 4 3 2 1 6 7 8 9
3 2 1 5 4 7 8 9 6
1
9 5
2 3 4 5 6 7 8 9 1
4 2 1 6 7
1
9 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1
9 9
1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1
1
9 9
9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9
1
9 9
9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
1
1 1
8
9
89
1 1
9
8
89
1 1
1
2
12
1 1
2
1
12
1 1
9
9
9
1 1
1
1
1
4 5
3 2 4 5
1 6 5 9 8
5
3 2
4 5 6
1 5
5
5 4
1 3 5 6 7
2 4 3 9
3
5 5
1 3 5 7 9
2 4 6 8 9
9
2 2
1 8
2 8
8
5 5
5 6 7 8 9
1 2 3 4 5
5
5 5
1 2 3 4 5
1 2 3 4 5
1
5 5
1 2 3 4 5
2 3 4 5 6
2
2 2
1 5
2 5
5
4 4
1 3 5 8
2 4 6 8
8
3 3
1 5 3
2 5 7
5
3 3
3 6 8
2 6 9
6
2 2
1 4
2 4
4
5 3
3 4 5 6 7
1 5 9
5
4 4
1 2 3 4
2 5 6 7
2
5 5
1 2 3 4 5
9 2 1 7 5
1
2 2
1 3
2 3
3
3 3
3 2 1
3 2 1
1
3 3
1 3 5
2 3 6
3
3 3
5 6 7
5 6 7
5
1 2
5
2 5
5
3 3
2 4 9
7 8 9
9
3 3
1 2 4
3 4 5
4
3 2
1 4 9
2 4
4
3 3
3 5 6
1 5 9
5
3 2
1 2 4
3 4
4
2 4
8 9
1 2 3 9
9
1 2
9
8 9
9
3 2
1 2 4
4 2
2
2 3
4 5
1 3 5
5
3 2
1 2 3
2 3
2
4 3
1 3 5 9
2 8 9
9
2 2
1 9
9 2
9
import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split() 
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))

#--------------------------------WhiteHat010--------------------------------#
n,m = get_int_list()
lst1 = get_int_list()
lst2 = get_int_list()
l1 = min(lst1)
l2 = min(lst2)


lst = []
for i in lst1:
    for j in lst2:
        if i == j:
            lst.append(i)

if len(lst) != 0:
    print(min(lst))
elif l1 < l2:
    print(l1*10 + l2)
else:
    print(l2*10 + l1)