#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 0; i < m; i++) cin >> a[i];
  for (int j = 0; j < n; j++) cin >> b[j];
  sort(a, a + m);
  sort(b, b + n);
  int flag = 0, ans;
  for (int i = 0, j = 0; i < m && j < n;) {
    if (a[i] == b[j]) {
      ans = a[i];
      flag = 1;
      break;
    } else if (a[i] < b[j])
      i++;
    else if (a[i] > b[j])
      j++;
  }
  if (flag == 1) {
    cout << ans << endl;
  } else {
    if (a[0] == b[0])
      cout << a[0] << endl;
    else {
      if (a[0] < b[0])
        cout << a[0] * 10 + b[0] << endl;
      else
        cout << b[0] * 10 + a[0] << endl;
    }
  }
}
