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