#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

N, M = [int (i) for i in raw_input ().split ()]
a = [int (i) for i in raw_input ().split ()]
b = [int (i) for i in raw_input ().split ()]
S = set (a).intersection (set (b))
S.add (100)
a, b = min (a), min (b)
print min (min (S), min (10 * a + b, 10 * b + a))

