#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x[1000], y[1000], xx = 1e9, yy = 1e9;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] < xx) xx = x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
    if (y[i] < yy) yy = y[i];
  }
  if (xx == yy) {
    cout << xx;
    return 0;
  }
  if (xx < yy)
    for (int i = 0; i < n; i++)
      if (y[i] == xx) {
        cout << xx;
        return 0;
      }
  if (yy < xx)
    for (int i = 0; i < n; i++)
      if (x[i] == yy) {
        cout << yy;
        return 0;
      }
  if (xx > yy) {
    cout << yy << xx;
    return 0;
  }
  cout << xx << yy;
}
