def mmi(a, m):
    """
    Find the modular multiplicative inverse of a.

    :param a int - key used in ciphering.
    :param m int - the number of letters in the alphabet.
    :return int - The MMI
    """
    #an mod m = 1
    result = a
    n = 1
    while result != 1:
        n += 1
        result = a * n % m
        while result > m:
            result = result % m

    return n