# -*- coding: utf-8 -*-
"""
Created on Mon Oct 16 22:41:40 2017

@author: nipa
"""
def solution(list1,list2):
    if list1 & list2: print(min(list1 & list2))
    else: print(min(min(list1)+min(list2), min(list2)+min(list1)))
    
if __name__=="__main__":
    a, b =  input().split()
    list1 = set(input().split())
    list2 = set(input().split())
    solution(list1,list2)
