#include<bits/stdc++.h>

using namespace std;

#define key(m) m->first
#define val(m) m->second
#define pb(i) push_back(i)
#define gcd(a,b) __gcd(a,b)
#define mp(i,j) make_pair(i,j)
#define all(i) i.begin(),i.end()
#define lcm(a,b) (a)*(b)/gcd(a,b)
#define rall(i) i.rbegin(),i.rend()
#define lp(i,j,k) for(int i=j;i<k;i++)
#define dlp(i,j,k) for(int i=j-1;i>=k;i--)

typedef set<int> si;
typedef long long ll;
typedef set<string> ss;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int,int> mii;
typedef vector<string> vs;
typedef map<char,int> mci;
typedef map<string,int> msi;
typedef map<string,string> mss;
typedef vector<pair<int,int>> vp;
typedef map<int,pair<int,int>> mip;
typedef vector<pair<string,string>> vps;


int main()
{

	ios::sync_with_stdio(false);
	cin.tie(false);

	int n,m,k,mn1=20,mn2=20;cin>>n>>m;
	mii mp1,mp2;
	vi v(n+m+5);
	lp(i,0,n){
        cin>>v[i];
        mp1[v[i]]=1;
        mn1=min(mn1,v[i]);
	}lp(i,0,m){
        cin>>v[i+n];
        mp2[v[i+n]]=1;
        mn2=min(mn2,v[i+n]);
	}sort(all(v));
	lp(i,0,n+m){
        if(mp1[v[i]] && mp2[v[i]]){
            cout<<v[i];
            return 0;
        }
	}cout<<min(mn1,mn2)<<max(mn1,mn2);
}

