#include <iostream>
using namespace std;
int f(int a[], int n, int b[], int m) {
int r = -1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i] == b[j] && (r == -1 || a[i] < r))
r = a[i];
return r;
}
int main() {
int x1[] = {6, 5, 3, 4, 8, 2};
int x2[] = {5, 1, 7, 3, 9, 0, 11, 4};
cout << f(x1, 6, x2, 8);
return 0;
}