Rock Paper Scissors Machine

Given two RPS strings, choose where in the opponent's longer string to start matching your shorter string and report the most wins.

Medium5StringString matchingBrute forcePrefix sumNo attempts yetTime limit1sMemory limit512 MB

Problem

A rock paper scissors machine plays rock, paper, or scissors at random. You own a small machine that works the same way. Before the game starts, the opposing machine writes down the list of nn choices it will play, and your machine writes down its own list of mm choices. You know both lists. Every entry is rock, paper, or scissors, where R means rock, P means paper, and S means scissors.

The game compares the two lists from the front, one entry against one entry. Before the first match you may skip as many entries at the front of the opposing list as you want. The first entry left after the skipping plays against the first entry of your list. Once the game starts you cannot skip any more, and the machines play one match after another until either list runs out. If the opposing list runs out while entries of your list remain, the game ends there. A draw does not count.

For example, if the opposing list is RSPPSSSRRPPR and your list is RRRR, skipping three entries or four entries wins three matches, and no other start wins more.

Figure 1. The best starting position when n=12n = 12 and m=4m = 4.

Given the two lists, find the largest number of matches your machine wins.

Input

The first line has two integers nn and mm (1m<n1000001 \le m < n \le 100000), where nn is the length of the opposing machine's list and mm is the length of your machine's list. The second line has the list of the opposing machine and the third line has the list of your machine, each written as a string of R, P, and S.

Output

Print the largest number of matches your machine wins on the first line.