#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, cnt11 = 0, cnt12 = 0, cnt13 = 0, cnt14 = 0, cnt15 = 0, cnt16 = 0,
            cnt17 = 0, cnt18 = 0, cnt19 = 0;
  int cnt21 = 0, cnt22 = 0, cnt23 = 0, cnt24 = 0, cnt25 = 0, cnt26 = 0,
      cnt27 = 0, cnt28 = 0, cnt29 = 0;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      cnt11++;
    }
    if (a[i] == 2) {
      cnt12++;
    }
    if (a[i] == 3) {
      cnt13++;
    }
    if (a[i] == 4) {
      cnt14++;
    }
    if (a[i] == 5) {
      cnt15++;
    }
    if (a[i] == 6) {
      cnt16++;
    }
    if (a[i] == 7) {
      cnt17++;
    }
    if (a[i] == 8) {
      cnt18++;
    }
    if (a[i] == 9) {
      cnt19++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (b[i] == 1) {
      cnt21++;
    }
    if (b[i] == 2) {
      cnt22++;
    }
    if (b[i] == 3) {
      cnt23++;
    }
    if (b[i] == 4) {
      cnt24++;
    }
    if (b[i] == 5) {
      cnt25++;
    }
    if (b[i] == 6) {
      cnt26++;
    }
    if (b[i] == 7) {
      cnt27++;
    }
    if (b[i] == 8) {
      cnt28++;
    }
    if (b[i] == 9) {
      cnt29++;
    }
  }
  if (cnt11 > 0 && cnt21 > 0) {
    cout << "1" << endl;
  } else if (cnt12 > 0 && cnt22 > 0) {
    cout << "2" << endl;
  } else if (cnt13 > 0 && cnt23 > 0) {
    cout << "3" << endl;
  } else if (cnt14 > 0 && cnt24 > 0) {
    cout << "4" << endl;
  } else if (cnt15 > 0 && cnt25 > 0) {
    cout << "5" << endl;
  } else if (cnt16 > 0 && cnt26 > 0) {
    cout << "6" << endl;
  } else if (cnt17 > 0 && cnt27 > 0) {
    cout << "7" << endl;
  } else if (cnt18 > 0 && cnt28 > 0) {
    cout << "8" << endl;
  } else if (cnt19 > 0 && cnt29 > 0) {
    cout << "9" << endl;
  } else {
    if (a[0] == b[0]) {
      cout << a[0] << endl;
    }
    if (a[0] > b[0]) {
      cout << b[0] << a[0] << endl;
    }
    if (a[0] < b[0]) {
      cout << a[0] << b[0] << endl;
    }
  }
  return 0;
}
