#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
int a = INT_MAX, b = INT_MAX;
while(n--)
{
int x;
cin >> x;
a = min(a, x);
}
while(m--)
{
int x;
cin >> x;
b = min(b, x);
}
cout << a + b << "\n";
return 0;
}