# Arup Guha
# Finished on 12/29/2025
# Solution to 2025 SER D1/D2 Problem: One Way Only

# Returns the encoding of the string s in streaks, a list of numbers which is how many
# repetitions of each character there are.
def mkseq(s):

    # Store the streaks here.
    streak = []
    i = 0

    # Go to end of string.
    while i < len(s):

        # Set up current streak.
        curC = s[i]
        j = i
        while j<len(s) and s[j] == s[i]:
            j += 1

        # Add it.
        streak.append(j-i)

        # Our new starting spot.
        i = j
        
    return streak

# Solves an instance of the problems with r rows, c columns and the direction string s.
def solve(r,c,s):

    # Not sure if I need this. I just put it in...
    if r == 1 or c == 1:
        return 0

    # We need this.
    streaks = mkseq(s)

    # This is the least blocks we have to place "to the left" of the path.
    minLeft = solveSide(streaks, s[0],True)

    # And to the right...
    minRight = solveSide(streaks, s[0],False)

    # Here is our final answer.
    return minLeft+minRight

# Returns the minimum answer for limiting the left side if isLeft is true, and the right side
# otherwise.
def solveSide(streaks, c, isLeft):

    # These are the cases we want to ignore the first streak.
    if isLeft and c == 'D':
        streaks = streaks[1:]
    elif not isLeft and c == 'R':
        streaks = streaks[1:]
        
    # All the down streaks from left or right streaks from right.
    dLeft = 0
    for i in range(1,len(streaks),2):
        dLeft += streaks[i]

    # This is our current answer.
    cur = dLeft
    res = cur

    # Go through each pair.
    for i in range(0,len(streaks),2):

        # So, we could block this and remove the block on the next item...
        cur += streaks[i]
        if i+1 < len(streaks):
            cur -= streaks[i+1]

        # Update if this is better.
        res = min(res, cur)

    return res

# Get input and solve.
toks = input().split()
r = int(toks[0])
c = int(toks[1])
s = input().strip()
print(solve(r,c,s))
