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

def main():
    a, b = map(int, input().split())
    arr1 = sorted(list(map(int, input().split())))
    arr2 = sorted(list(map(int, input().split())))
    flag = False
    for i in range(len(arr1)):
        if flag:
            break
        for j in range(len(arr2)):
            if (arr1[i] == arr2[j]):
                print(arr1[i])
                flag = True
                break
    if not flag:
        print(min(arr1[0], arr2[0]), max(arr1[0], arr2[0]), sep='')


if __name__ == "__main__":
    main()
