#include<bits/stdc++.h>

 #define f first
 #define s second
 #define pb push_back


using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

ll n;
ll m;
vector<ll> a;
vector<ll> b;
ll memo [2000][2000];


ll lcs (ll x, ll y)
{

    if(x==n){return m-y;}
    if(y==m){return n-x;}
    if(memo[x][y]!=-1){return memo[x][y];}
    if(a[x]==b[y]){return memo[x][y]=lcs(x+1,y+1);}

    return memo[x][y]=min(1+lcs(x+1,y+1),min(1+lcs(x+1,y),1+lcs(x,y+1)));
}

int main ()
{
    ios::sync_with_stdio(0);
cin.tie(0);

cin>>n>>m;
for(int i=0;i<n;i++)
{
    ll c;
    cin>>c;
    a.pb(c);
}
for(int i=0;i<m;i++)
{
    ll c;
    cin>>c;
    b.pb(c);
}
memset(memo,-1,sizeof(memo));
cout<<lcs(0,0)<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define V vector
#define debug(v) for(auto i: v) cout << i << " "; cout << endl;
#define vcin(v) rep(i, v.size()) cin >> v[i]
#define wcin(v, w) rep(i, v.size()) cin >>v[i] >>w[i]
#define r0 return 0;

int main(){
    ll n,m;
    cin >>n >>m;
    V<ll> a(n),b(m);
    vcin(a);
    vcin(b);

    unordered_set<ll> num;
    for(ll i:a)num.insert(i);
    for(ll i:b)num.insert(i);
    unordered_set<ll> numa=num;
    unordered_set<ll> numb=num;
    for(ll i:a)numa.erase(i);
    for(ll i:b)numb.erase(i);
    V<ll> ans;
    for(ll i:numa)ans.push_back(i);
    for(ll i:numb)ans.push_back(i);
    sort(all(ans));
    for(ll i:ans)cout <<i <<" ";
}