@staticmethod
def b():
    (s, t) = sys.stdin.read().split()
    y = 0
    x = 0
    z = 0
    for c in s:
        if (c == '?'):
            z += 1
        elif (c == 'L'):
            x -= 1
        elif (c == 'R'):
            x += 1
        elif (c == 'D'):
            y -= 1
        elif (c == 'U'):
            y += 1
    d = (abs(y) + abs(x))
    if (t == '1'):
        print((d + z))
    else:
        print(max((d - z), ((d - z) & 1)))
@staticmethod
def b():
    (s, t) = sys.stdin.read().split()
    y = 0
    x = 0
    z = 0
    for c in s:
        if (c == '?'):
            z += 1
        elif (c == 'L'):
            x -= 1
        elif (c == 'R'):
            x += 1
        elif (c == 'D'):
            y -= 1
        elif (c == 'U'):
            y += 1
    d = (abs(y) + abs(x))
    if (t == '1'):
        print((d + z))
    else:
        print(max((d - z), ((d - z) & 1)))