#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<conio.h>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;


int main() {
	//freopen("out.txt", "wt", stdout); freopen("in.txt", "rt", stdin);
	vector<int> a;
	vector<int> b;

	int n;
	int m;
	int g; 
	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		cin >> g;
		a.push_back(g);
	}

	for (int i = 0; i < n; i++) {
		cin >> g;
		b.push_back(g);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if (a[0] != b[0]) {
		if (a[0] < b[0]) {
			cout << a[0] * 10 + b[0];
		}
		else {
			cout << b[0] * 10 + b[0];
		}
	}
	else {
		cout << a[0];
	}
	return 0;
}