#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define mp make_pair
#define pb push_back
#define MAXN 1000100
typedef long long ll;

struct blk_haha
{
	int l,val;
}qw[MAXN],qb[MAXN];

int n,m,f[MAXN],sumd[MAXN],qwl,qwr,qbl,qbr;
char s[MAXN],t[MAXN];

int getsum(int l,int r)
{
	int tmp=0;
	if(sumd[l]-sumd[l-1]==1)tmp=sumd[r]-sumd[l-1];
	else tmp=sumd[r]-sumd[l-1]+1;
	if(tmp&1)return (tmp+1)/2;
	else return (tmp)/2+1;
}

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	scanf("%s",t+1);
	sumd[1]=1;
	rep(i,2,n)
	{
		if(t[i]!=t[i-1])
			sumd[i]=1;
		sumd[i]+=sumd[i-1];
	}
	qwl=qbl=1;
	rep(i,1,n)
	if(s[i]!=t[i])
	{
		f[i]=getsum(max(i-m+1,1),i)+f[max(i-m,0)];
		f[i]=min(f[i],1+f[i-1]);
		if(t[i]=='B')
		{		
			while(i-m>=qb[qbl].l && qbl<=qbr)
			{
				qbl++;
			}
			
			if(qbl<=qbr)
			{
				int l=qb[qbl].l;
				f[i]=min(f[i],getsum(l,i)+f[l-1]);
			}
			
			if(sumd[i]!=sumd[i-1])
			{
				int tmp=1+f[i-1];
				while(qbl<=qbr && tmp<=getsum(qb[qbr].l,i)+f[qb[qbr].l-1])
				{
					qbr--;
				}
				qbr++;
				qb[qbr].l=i;
			}
		}
		else
		{		
			while(i-m>=qw[qwl].l && qwl<=qwr)qwl++;
			
			if(qwl<=qwr)
			{
				int l=qw[qwl].l;
				f[i]=min(f[i],getsum(l,i)+f[l-1]);
			}
			
			if(sumd[i]!=sumd[i-1])
			{
				int tmp=1+f[i-1];
				while(qwl<=qwr && tmp<=getsum(qw[qwr].l,i)+f[qw[qwr].l-1])
				{
					qwr--;
				}
				qwr++;
				qw[qwr].l=i;
			}
		}
	}
	else 
	{
		f[i]=f[i-1];
		if(t[i]=='B')
		{
			if(sumd[i]!=sumd[i-1])
			{
				int tmp=1+f[i-1];
				while(qbl<=qbr && tmp<=getsum(qb[qbr].l,i)+f[qb[qbr].l-1])
				{
					qbr--;
				}
				qbr++;
				qb[qbr].l=i;
			}
		}
		else
		{
			if(sumd[i]!=sumd[i-1])
			{
				int tmp=1+f[i-1];
				while(qwl<=qwr && tmp<=getsum(qw[qwr].l,i)+f[qw[qwr].l-1])
				{
					qwr--;
				}
				qwr++;
				qw[qwr].l=i;
			}
		}
	}
	printf("%d\n",f[n]);
	return 0;
}

