#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using pll = pair; using vl = vector; using vll = vector; using vpll = vector; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define Rep(i, n) for (long long i = 0; i< (long long)(n); i++) #define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--) #define all(v) (v).begin(),(v).end() struct Edge{ int to; int weight; Edge(int t, int w) : to(t), weight(w){ } }; struct edge{ int from; int to; int weight; edge(int f,int t,int w) : from(f), to(t), weight(w){ } }; using Graph = vector>; using graph = vector>; using edges = vector; template inline bool chmin(T &a, T b){ if (a > b){ a = b; return true; } return false; } template inline bool chmax(T &a, T b){ if (a < b){ a = b; return true; } return false; } template T gcd(T a, T b){ if( b==0 ) return a; return gcd(b, a%b); } template T lcm(T a, T b){ return (a*b)/gcd(a,b); } int INF = 1e9+7; vector dx = {-1,0,1,0}; vector dy = {0,-1,0,1}; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; string s,t; cin >> s >> t; vector> dp(n+1,vector(m+1,INF)); dp[0][0] = 0; for(int i = -1; i=0 && j>=0){ if(s[i]==t[j]) chmin(dp[i+1][j+1],dp[i][j]); else chmin(dp[i+1][j+1],dp[i][j]+1); } if(i>=0) chmin(dp[i+1][j+1],dp[i][j+1]+1); if(j>=0) chmin(dp[i+1][j+1],dp[i+1][j]+1); } cout << dp[n][m] << endl; }