#include <bits/stdc++.h>
using namespace std;

void chmin(int &a, int b) { if(a>b) a=b; }

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> A(N+1, 0);
    vector<int> B(M+1, 0);
    vector<vector<int>> dp(N+1, vector<int>(M+1, INT_MAX));
    for (int i=1; i<=N; i++) { cin >> A[i]; }
    for (int i=1; i<=M; i++) { cin >> B[i]; }

    dp[0][0] = 0;
    for (int i=0; i<=N; i++) {
        for (int j=0; j<=M; j++) {
            int tmpa = INT_MAX;
            if (i>0) {
                //chmin(dp[i][j], dp[i-1][j] + 1);
                chmin(tmpa, dp[i-1][j] + 1);
            }

            if (j>0) {
                //chmin(dp[i][j], dp[i][j-1] + 1);
                chmin(tmpa, dp[i][j-1] + 1);
            }

            if (i>0 && j>0)  {
                //chmin(dp[i][j], dp[i-1][j-1] + !(A[i]==B[j])); // true is 1
                chmin(tmpa, dp[i-1][j-1] + !(A[i]==B[j])); // true is 1
            }
            if (i==0 && j== 0) dp[i][j] = 0;
            else dp[i][j] = tmpa;
            //cout << tmpa << " ";
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }

    cout << dp[N][M] << endl;

    return 0;
}
/*
    author: lone_star
    I love coding, particle physics and chilled beer.
*/

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;


long long mod(ll x, ll M){
    return ((x%M + M)%M);
}
long long add(ll a, ll b, ll m){
    return mod(mod(a,m)+mod(b,m),m);
}
long long mul(ll a, ll b, ll m){
    return mod(mod(a,m)*mod(b,m),m);
}


bool prime(ll s)
{
    if (s <= 1)  return false;
    if (s <= 3)  return true;
    if (s%2 == 0 || s%3 == 0) return false;

    for (ll i=5; i*i<=s; i=i+6)
        if (s%i == 0 || s%(i+2) == 0)
            return false;

    return true;
}

ll power(ll x, ll y)
{
    ll res = 1;


    while (y > 0) 
    {
        if (y & 1)
            res = (res * x);

        y = y >> 1;
        x = (x * x);
    }
    return res;
}


// ll power(ll x, ll y)
// {
//     ll ans = 1;
//     for(ll i=1;i<=y;++i)
//         ans*=x;
//     return ans;
// }


ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0) 
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

bool square(long double x)
{
    long double sr = sqrt(x);

    return ((sr - floor(sr)) == 0);
}




void solve()
{
    string a,b;
    cin>>a>>b;
    ll sum1=0,sum2=0;
    for(char ch : a)
        sum1+= ch-'0';
    for(char ch : b)
        sum2+= ch-'0';
    cout<<max(sum1,sum2)<<"\n";
}



int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll t=1;
    // cin>>t;
    
    ll z=1;
    while(t--)
    {
        // cout<<"Case #"<<z<<": ";
        solve();
        z++;
    }
}