#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define fk cerr<<"fk"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
const int N=(int)1e3+100;
int n,m,a[N],b[N],dp[N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);                             
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>n>>m;
    forn(i, n) cin>>a[i];
    forn(i, m) cin>>b[i];
    ms(dp,0x3f);
    dp[0][0]=0;
	for(int i=0; i<=n; ++i){
		for(int j=0; j<=m; ++j){
			if(i+1<=n) uin(dp[i+1][j],dp[i][j]+1);
			if(j+1<=m) uin(dp[i][j+1],dp[i][j]+1);
			if(i+1<=n && j+1<=m){
				uin(dp[i+1][j+1],dp[i][j]+(a[i]!=b[j]));
			}
		}
	}
    cout<<dp[n][m]<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    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 req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
ll mod = 998244353;
ll fanc(int n,int k){
    return min(k-1,2*n+1-k);
}
int main(){
    int n,k;cin >>n>>k;
    ll sum = 0;
    for(int i = max(2,2+k);i<=min(2*n,2*n+k);i++){
        sum += fanc(n,i)*fanc(n,i-k);
    }cout << sum <<endl;
}