#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, n, m, x, y, z, c = 0, sumx = 0, sumy = 0, ans1, ans2,
                                        ans3, ans4;
  string s, t;
  cin >> n >> m;
  bool r = false;
  vector<long long int> a(n), b(m);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (j = 0; j < m; j++) {
    cin >> b[j];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  x = a[0];
  y = b[0];
  if (x == y) {
    cout << x << endl;
  } else {
    r = false;
    if (x > y && n != 1 && m != 1) {
      for (i = 0; i < n; i++) {
        if (y == a[i]) {
          r = true;
          ans1 = y;
          break;
        }
      }
      if (r) {
        cout << y << endl;
      } else {
        cout << y << x << endl;
      }
    } else if (x < y && n != 1 && m != 1) {
      for (j = 0; j < m; j++) {
        if (x == b[j]) {
          r = true;
          break;
        }
      }
      if (r) {
        cout << x << endl;
      } else {
        cout << x << y << endl;
      }
    } else if (x > y && (n == 1) || (m == 1)) {
      if (n == 1) {
        r = false;
        for (j = 0; j < m; j++) {
          if (x == b[j]) {
            r = true;
            break;
          }
        }
        if (r) {
          cout << x << endl;
        } else {
          cout << y << x << endl;
        }
      } else {
        r = false;
        for (i = 0; i < n; i++) {
          if (y == a[i]) {
            r = true;
            break;
          }
        }
        if (r) {
          cout << y << endl;
        } else {
          cout << y << x << endl;
        }
      }
    } else if (x < y && (n == 1 || m == 1)) {
      if (n == 1) {
        r = false;
        for (j = 0; j < m; j++) {
          if (x == b[j]) {
            r = true;
            break;
          }
        }
        if (r) {
          cout << x << endl;
        } else {
          cout << x << y << endl;
        }
      } else {
        r = false;
        for (i = 0; i < n; i++) {
          if (y == a[i]) {
            r = true;
            break;
          }
        }
        if (r) {
          cout << y << endl;
        } else {
          cout << x << y << endl;
        }
      }
    }
  }
  return 0;
}
