#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define fi first
#define se second
#define pb push_back
#define pob pop_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<char,int> PCI;
typedef pair<int,char> PIC;
typedef vector<int> VI;
typedef vector<int,int> VII;
typedef unordered_map<int,int> UII;
typedef set<int> SI;
typedef vector<string> VS;
typedef vector<PII> VPII;
const int INF = 0x3f3f3f3f,MOD = 1e9 + 7;
const int N = 1010,M = N * 2;
const double PI = 3.1415926;
int n,m;
char a[N],b[N];
int f[N][N];
void solve(){
cin >> n >> a + 1;
cin >> m >> b + 1;
memset(f,0x3f,sizeof f);
for(int i = 0;i <= n;i++)f[i][0] = i;
for(int i = 0;i <= m;i++)f[0][i] = i;
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 - 1][j - 1] + 1,f[i][j]);
}
}
cout << f[n][m] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T = 1;//cin >> T;
while(T--)solve();
return 0;
}