#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int n, m;
char a[N], b[N];
int f[N][N];
int main (){
scanf("%d%s", &n, a + 1); //编辑距离问题的下标从1开始,因为涉及到 i-1, j-1
scanf("%d%s", &m, b + 1);
for (int i = 0; i <= m; i ++) f[0][i] = i; //处理边界 当A有0个字母,给它添m个B的
for (int j = 0; j <= n; j ++) f[j][0] = j; //处理边界 当B有0个字母,删掉n个A的
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++) {
f[i][j] = min(f[i - 1][j] + 1, f[i][j - 1] + 1);
if (a[i] == b[j])
f[i][j] = min(f[i][j], f[i - 1][j - 1]);
else f[i][j] = min(f[i][j], f[i - 1][j - 1] + 1);
}
cout << f[n][m] << endl;
return 0;
}