#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(int i=(r)-1;i>=(l);i--)
#define pb push_back
#define ins insert
#define se second
#define fi first
#define all(x) x.begin(),x.end()
using vi=vector<int>;
using vl=vector<ll>;
using vvi= vector<vector<int>>;
using vvl= vector<vector<ll>>;
using pii= pair<int,int>;
using pll= pair<ll,ll>;
const ll mod = INF;
const int dxn[9]={-1,0,1,-1,0,1,-1,0,1};
const int dyn[9]={-1,-1,-1,0,0,0,1,1,1};
const int dxf[4]={0,1,0,-1};
const int dyf[4]={-1,0,1,0};
const int maxn = 1000;


int main(){
    int n,m;
    ll a[maxn+1],b[maxn+1];
    ll dp[maxn+1][maxn+1]={0};

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

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

    repl(i,1,n+1){
        repl(j,1,m+1){
            int p=1;
            if(a[i]==b[j])p=0;
            dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+p);
        }
    }

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

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) (long long)(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
using ld = long double;

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; }

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;




signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  int x,y; cin>>x>>y;
  if(abs(x-y)<3) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}