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