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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int MOD=998244353;

signed main(void)
{
	IOS;
	int n,k; cin>>n>>k;
	int vv[2*n+1]={};
	for(int i = 2; i <= 2*n; i++) {
		int lo=max(1ll,i-n);
		int hi = i-lo;
		vv[i] = hi-lo+1;
	}
	// for(int i = 2; i<=2*n; i++)
	// 	cout<<vv[i]<<" ";
	// cout<<endl;
	int ans=0;
	for(int i = 2; i <= 2*n; i++) {
		int s = i-k;
		if(s<2 || s > 2*n)
			continue;
		ans += vv[s]*vv[i];
		// ans %= MOD;
	}
	cout<<ans<<endl;
	return 0;
}
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/rational.hpp>

// using bigint = boost::multiprecision::cpp_int;
// using fraction = boost::rational<bigint>;
using namespace std;

#define pb push_back
#define eb emplace_back
#define unused [[maybe_unused]]
#define tempT template<class T>
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl
#define ans_exit(x) { cout << x << endl; exit(0); }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++)

using ll   unused = long long;
using ld   unused = long double;
using vl   unused = vector<ll>;
using vvl  unused = vector<vl>;
using vvvl unused = vector<vvl>;
using lp   unused = pair<ll, ll>;
using lmap unused = map<int, int>;

unused constexpr ll MOD = 1e9 + 7;
unused constexpr ll INF = 1 << 30;
unused constexpr ll LINF = 1LL << 62;
unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1};
unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1};
unused inline bool bit(ll b, ll i) { return b & (1LL << i); }
unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; }
unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); }
unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); }
tempT unused inline bool in_range(T a, T x, T b) { return a <= x && x < b; }
unused inline bool in_range(ll x, ll b) { return in_range(0LL, x, b); }
tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; }
tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; }

int main() {
    ll n, m;
    cin >> n >> m;

    vl a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vvl dp(n+1, vl(m+1, LINF));

    rep(i, n + 1) dp[i][0] = i;
    rep(j, m + 1) dp[0][j] = j;

    rep(i, n) {
        rep(j, m) {
            if(a[i] == b[j]) {
                chmin(dp[i+1][j+1], dp[i][j]);
            } else {
                chmin(dp[i+1][j+1], min(dp[i+1][j], dp[i][j+1]) + 1);
                chmin(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }

    cout << dp[n][m] << endl;
}