#include <bits/stdc++.h>
#define endl '\n'
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
using namespace std;
template < class T, class T2> inline int chkmax( T & x, const T2 & y) { return x < y ? x = y, 1 : 0 ; }
template < class T, class T2> inline int chkmin( T & x, const T2 & y) { return x > y ? x = y, 1 : 0 ; }
const int MAXN = ( 1 << 20 ) ;
const int OFFSET = ( int ) 3e5 + 152 ;
int n, k;
string s;
void read( )
{
cin >> n >> k >> s;
}
int psum[ MAXN] ;
int dp[ MAXN] ;
int tr[ 4 * MAXN] ;
multiset< int > P[ OFFSET * 2 ] ;
void init( int l, int r, int idx)
{
if ( l == r)
{
tr[ idx] = ( int ) 1e9 ;
return ;
}
int mid = ( l + r) >> 1 ;
init( l, mid, 2 * idx + 1 ) ;
init( mid + 1 , r, 2 * idx + 2 ) ;
tr[ idx] = min( tr[ 2 * idx + 1 ] , tr[ 2 * idx + 2 ] ) ;
}
void add( int pos, int val, int l, int r, int idx)
{
if ( l == r)
{
P[ OFFSET + pos] .insert ( val) ;
tr[ idx] = * P[ OFFSET + pos] .begin ( ) ;
return ;
}
int mid = ( l + r) >> 1 ;
if ( mid < pos) add( pos, val, mid + 1 , r, 2 * idx + 2 ) ;
else add( pos, val, l, mid, 2 * idx + 1 ) ;
tr[ idx] = min( tr[ 2 * idx + 1 ] , tr[ 2 * idx + 2 ] ) ;
}
void rem( int pos, int val, int l, int r, int idx)
{
if ( l == r)
{
P[ OFFSET + pos] .erase ( P[ OFFSET + pos] .find ( val) ) ;
tr[ idx] = P[ OFFSET + pos] .empty ( ) ? ( int ) 1e9 : * P[ OFFSET + pos] .begin ( ) ;
return ;
}
int mid = ( l + r) >> 1 ;
if ( mid < pos) rem( pos, val, mid + 1 , r, 2 * idx + 2 ) ;
else rem( pos, val, l, mid, 2 * idx + 1 ) ;
tr[ idx] = min( tr[ 2 * idx + 1 ] , tr[ 2 * idx + 2 ] ) ;
}
int query( int ql, int qr, int l, int r, int idx)
{
if ( qr < l || r < ql) return ( int ) 1e9 ;
if ( ql <= l && r <= qr)
return tr[ idx] ;
int mid = ( l + r) >> 1 ;
return min( query( ql, qr, l, mid, 2 * idx + 1 ) , query( ql, qr, mid + 1 , r, 2 * idx + 2 ) ) ;
}
void solve( )
{
for ( int i = 1 ; i <= n; i++ )
psum[ i] = psum[ i - 1 ] + ( s[ i - 1 ] == 'G' ? 1 : - 1 ) ;
int N = n + 42 ;
init( - N, N, 0 ) ;
add( 0 , 0 , - N, N, 0 ) ;
for ( int i = 1 ; i <= n; i++ )
{
dp[ i] = query( - N, psum[ i] , - N, N, 0 ) + 1 ;
chkmin( dp[ i] , query( psum[ i] + 1 , N, - N, N, 0 ) ) ;
add( psum[ i] , dp[ i] , - N, N, 0 ) ;
if ( i >= k)
rem( psum[ i - k] , dp[ i - k] , - N, N, 0 ) ;
}
cout << dp[ n] << endl;
}
int main( )
{
freopen ( "redistricting.in" , "r" , stdin ) ;
freopen ( "redistricting.out" , "w" , stdout ) ;
ios_base:: sync_with_stdio ( false ) ;
cin .tie ( NULL ) ;
read( ) ;
solve( ) ;
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgovLyNwcmFnbWEgR0NDIG9wdGltaXplICgiTzMiKQovLyNwcmFnbWEgR0NDIHRhcmdldCAoInNzZTQiKQoKI2RlZmluZSBTWih4KSAoKGludCl4LnNpemUoKSkKI2RlZmluZSBBTEwoVikgVi5iZWdpbigpLCBWLmVuZCgpCiNkZWZpbmUgTF9CIGxvd2VyX2JvdW5kCiNkZWZpbmUgVV9CIHVwcGVyX2JvdW5kCiNkZWZpbmUgcGIgcHVzaF9iYWNrCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0ZW1wbGF0ZTxjbGFzcyBULCBjbGFzcyBUMj4gaW5saW5lIGludCBjaGttYXgoVCAmeCw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