// Arup Guha
// 11/13/2017
// Solution to 2017 SER D1 Problem: Ducks in a Row

import java.util.*;

public class ducks {

	// Good enough for this question.
	final public static int NOSOL = 1000000;

	public static int numRuns;
	public static int minLen;
	public static String input;
	public static int n;
	public static HashMap<Long,Integer> memo;

	public static void main(String[] args) {

		// Get the input.
		Scanner stdin = new Scanner(System.in);
		minLen = stdin.nextInt();
		numRuns = stdin.nextInt();
		input = stdin.next();
		n = input.length();

		// Store old cases here.
		memo = new HashMap<Long,Integer>();

		// Run it!
		int res = go(0, numRuns, 0, 0);

		// Print the result.
		if (res == NOSOL)
			System.out.println(-1);
		else
			System.out.println(res);
	}

	// preDucks = # of Ducks right before, runsNeeded = # of runs needed,
	// curPos = current index in string,
	// wand = 0 (if you didn't use the wand on the last item), 1 (if you did)
	public static int go(int preDucks, int runsNeeded, int curPos, int wand) {


		// Basic base cases. (wand = 1 means we need to count the last time we used the wand...)
		if (runsNeeded == 0) return wand;
		if (runsNeeded == 1 && preDucks == minLen) return wand;

		// Couldn't do it.
		if (curPos == input.length()) return NOSOL;

		// This is key, we don't have enough characters to complete this!
		if (runsNeeded*minLen - preDucks + runsNeeded-1 > n-curPos) return NOSOL;

		// We've done this case before...
		long key = getKey(preDucks, runsNeeded, curPos, wand);
		if (memo.containsKey(key)) return memo.get(key);

		char c = input.charAt(curPos);

		// Run to add if we put a 'G' here.
		int sub = preDucks == minLen ? 1 : 0;

		int wandOff = (c == 'D') ? 	wand + go(Math.min(preDucks+1, minLen), runsNeeded, curPos+1, 0) :
									wand + go(0, runsNeeded-sub, curPos+1, 0);

		int wandOn =  (c == 'G') ? 	go(Math.min(preDucks+1, minLen), runsNeeded, curPos+1, 1) :
									go(0, runsNeeded-sub, curPos+1, 1);

		// Best answer is the smaller of the two options (keeping the wand on or off for this letter)
		memo.put(key, Math.min(wandOff, wandOn));
		return Math.min(wandOff, wandOn);
	}

	// Easier to bit shift than multiply stuff...
	public static long getKey(int preDucks, int runsNeeded, int curPos, int wand) {
		return ((preDucks*1L) << 23) + ((runsNeeded*1L) << 12) + (curPos << 1) + wand;
	}
}