#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> A(N), B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];

    vector<vector<ll>> dp(N+1,vector<ll>(M+1,inf));
    rep(i,N+1) dp[i][0] = i;
    rep(i,M+1) dp[0][i] = i;
    repp(i,1,N+1) repp(j,1,M+1) {
        ll a = A[i-1], b = B[j-1];
        chmin(dp[i][j],dp[i-1][j]+1);
        chmin(dp[i][j],dp[i][j-1]+1);
        if (a==b) {
            chmin(dp[i][j],dp[i-1][j-1]);
        } else {
            chmin(dp[i][j],dp[i-1][j-1]+1);
        }
    }
    ll ans = dp[N][M];

    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll solve(int L, int R){
  vector<ll> memo(1<<21, -1);
  auto f = [&](auto self, int L, int R) -> ll {
    // L < x <= R であって、gcd(x,y) == 1 となるものを数える
    auto key = L + R;
    if(memo[key] != -1) return memo[key];
    
    ll res = ll(R - L) * (R - L);
    int d = max(L, R);
    while(d > 1){
      int nxt_d = max(L / (L / d + 1), R / (R / d + 1));
      res -= (d - nxt_d) * self(self, L / d, R / d);
      d = nxt_d;
    }
    memo[key] = res;
    return res;
  };
  
  auto g = [&](int L, int R) -> ll {
    ll res = 0;
    int d = max(L, R);
    while(d){
      int nxt_d = max(L / (L / d + 1), R / (R / d + 1));
      ll cnt = max(0, min(d, R) - max(nxt_d, L));
      res += cnt * (R / d - L / d);
      d = nxt_d;
    }
    return res;
  };
  
  --L;
  ll ans = ll(R - L) * (R - L);
  ans -= f(f, L, R) + 2 * g(L, R);
  ans += 2 * (L < 1 ? R - L : 0) + (R - L);
  ans -= L < 1;
  return ans;
}

int main(){
  int L, R;
  cin >> L >> R;
  ll ans = solve(L, R);
  cout << ans << endl;
  return 0;
}  
