a, b = map(int, input().split());
x = list(map(int, input().split()));
y = list(map(int, input().split()));

x.sort();
y.sort();
for i in x:
  if i in y:
    print(i);
    exit(0);

print(str(min(x[0], y[0])) + str(max(x[0], y[0])));
