#include <bits/stdc++.h>
typedef long long ll;
typedef long l;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vii;
typedef std::queue<int> qi;
typedef std::priority_queue<int, std::vector<int>, std::less<int>> pqi;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repi(i, a, b) for(int i = a; i < (int)(b); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define inf 2147483647
#define inf64 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;

void solution()
{
    int a[1005] = {};
    int b[1005] = {};
    int dp[1005][1005] = {};

    int n, m;
    cin >> n >> m;

    rep(i, n) {
        cin >> a[i];
        dp[i+1][0] = i+1;
    }
    rep(i, m){
        cin >> b[i];
        dp[0][i+1] = i+1;
    }

    repi(i, 1, n + 1) {
        repi(j, 1, m + 1) {
            dp[i][j] = min(dp[i-1][j]+1, dp[i][j-1]+1);
            dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (a[i-1] != b[j-1]));
        }
    }

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

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solution();
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for(ll a = 2; a <= 2 * n; a++) {
    ll b = a - k; 
    if (b < 2 || b > 2*n) continue;
    if (a <=n) {
      if(b <=n) {
        ans += (a-1) * (b-1);
      } else {
        ans += (a-1) * (2 * n - b + 1);
      }
    } else {
      if(b <=n) {
        ans += (2 * n - a + 1) * (b-1);
      } else {
        ans += (2 * n - a + 1) * (2 * n - b + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}