A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").

You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?

Input

The first line of input contains a string commands — the original list of commands. The string commands contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".

The second line contains an integer n (1 ≤ n ≤ 50) — the number of commands you have to change in the list.

Output

Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.

Examples

Input

FT
1


Output

2


Input

FFFTFFF
2


Output

6

Note

In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.

In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.
import java.io.Closeable;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		QuickScanner in = new QuickScanner(inputStream);
		ExtendedPrintWriter out = new ExtendedPrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public static final int INF = Integer.MAX_VALUE / 20;

	public void solve(int testNumber, QuickScanner in, ExtendedPrintWriter out) {
        char[] commands = (" " + in.next()).toCharArray();
        int n = commands.length - 1;
        int toChange = in.nextInt();
        int[][][] minPosition = new int[n + 1][toChange + 1][2];
        int[][][] maxPosition = new int[n + 1][toChange + 1][2];
        ArrayUtils.fill(minPosition, INF);
        ArrayUtils.fill(maxPosition, -INF);
        Arrays.fill(minPosition[0][0], 0);
        Arrays.fill(maxPosition[0][0], 0);
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= toChange; j++) {
                for (int k = 0; k < 2; k++) {
                    //not change
                    if (commands[i] == 'T') {
                        minPosition[i][j][k] = Math.min(minPosition[i][j][k], minPosition[i - 1][j][1 - k]);
                        maxPosition[i][j][k] = Math.max(maxPosition[i][j][k], maxPosition[i - 1][j][1 - k]);
                    } else {
                        minPosition[i][j][k] = Math.min(minPosition[i][j][k], minPosition[i - 1][j][k] + toward(k));
                        maxPosition[i][j][k] = Math.max(maxPosition[i][j][k], maxPosition[i - 1][j][k] + toward(k));
                    }
                    //change
                    if (j > 0) {
                        if (commands[i] == 'T') {
                            minPosition[i][j][k] = Math.min(minPosition[i][j][k], minPosition[i - 1][j - 1][k] + toward(k));
                            maxPosition[i][j][k] = Math.max(maxPosition[i][j][k], maxPosition[i - 1][j - 1][k] + toward(k));
                        } else {
                            minPosition[i][j][k] = Math.min(minPosition[i][j][k], minPosition[i - 1][j - 1][1 - k]);
                            maxPosition[i][j][k] = Math.max(maxPosition[i][j][k], maxPosition[i - 1][j - 1][1 - k]);
                        }
                    }
                }
            }
        }
        int answer = 0;
        for (int j = toChange % 2; j <= toChange; j += 2) {
            for (int k = 0; k < 2; k++) {
                answer = Math.max(answer, -minPosition[n][j][k]);
                answer = Math.max(answer, maxPosition[n][j][k]);
            }
        }
        out.println(answer);

    }

    private int toward(int x) {
        return x == 0 ? 1 : -1;
    }
}

class QuickScanner implements Iterator<String>, Closeable {
    BufferedReader reader;
    StringTokenizer tokenizer;
    boolean endOfFile = false;

    public QuickScanner(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = null;
    }

    public boolean hasNext() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                checkNext();
            } catch (NoSuchElementException ignored) {
            }

        }
        return !endOfFile;
    }

    private void checkNext() {
        if (endOfFile) {
            throw new NoSuchElementException();
        }
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (Exception e) {
            endOfFile = true;
            throw new NoSuchElementException();
        }
    }

    public String next() {
        checkNext();
        return tokenizer.nextToken();
    }

    public void remove() {
        throw new UnsupportedOperationException();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public void close() {
        try {
            reader.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}

class ExtendedPrintWriter extends PrintWriter {


    public ExtendedPrintWriter(Writer out) {
        super(out);
    }

    public ExtendedPrintWriter(OutputStream out) {
        super(out);
    }

    }

class ArrayUtils {

    private ArrayUtils() {
    }

    public static void fill(int[][] array, int val) {
        for (int[] subArray : array) {
            Arrays.fill(subArray, val);
        }
    }

    public static void fill(int[][][] array, int val) {
        for (int[][] subArray : array) {
            ArrayUtils.fill(subArray, val);
        }
    }

    }

