#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
using namespace std;
const int N = 1e6 + 5;
const ll inf = -1e18;
const int MOD = 1e9 + 7;
ll n, ans, cur, pos = -1;
string s, t;
std::vector<ll> v;
ll querry(ll x, ll y){
ll ct = 0;
swap(s[x], s[y]);
for(int i = 0; i < n; i++){
if(s[i] != t[i])
break;
ct = i + 1;
}
swap(s[x], s[y]);
return ct;
}
int main(){
fast;
cin >> n >> s >> t;
for(int i = 0; i < n; i++){
if(s[i] != t[i]){
pos = i;
break;
}
}
if(pos == -1){
return cout << n, 0;
}
ans = pos;
for(int i = pos + 1; i < n; i++){
if(s[i] == t[pos])
v.push_back(i);
}
ll lo = -1, hi = (int)v.size(), mid;
while(hi - lo > 1){
ll mid = hi + lo >> 1;
cur = querry(pos, v[mid]);
if(ans == cur)
hi = mid;
else{
ans = cur;
lo = mid;
}
}
cout << ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmFzdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoTlVMTCk7Y291dC50aWUoTlVMTCkKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU2ICsgNTsKY29uc3QgbGwgaW5mID0gLTFlMTg7CmNvbnN0IGludCBNT0QgPSAxZTkgKyA3OwoKbGwgbiwgYW5zLCBjdXIsIHBvcyA9IC0xOwpzdHJpbmcgcywgdDsKc3RkOjp2ZWN0b3I8bGw+IHY7CmxsIHF1ZXJyeShsbCB4LCBsbCB5KXsKCWxsIGN0ID0gMDsKCXN3YXAoc1t4XSwgc1t5XSk7Cglmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKCQlpZihzW2ldICE9IHRbaV0pCgkJCWJyZWFrOwoJCWN0ID0gaSArIDE7Cgl9Cglzd2FwKHNbeF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