def extended_euclidean_algorithm(m, n):
    """
    Extended Euclidean Algorithm.

    Finds 2 numbers a and b such that it satisfies
    the equation am + bn = gcd(m, n) (a.k.a Bezout's Identity)
    """
    a = 0
    a_prime = 1
    b = 1
    b_prime = 0
    q = 0
    r = 0
    if m > n:
        c = m
        d = n
    else:
        c = n
        d = m

    while True:
        q = int(c / d)
        r = c % d
        if r == 0:
            break
        c = d
        d = r

        t = a_prime
        a_prime = a
        a = t - q * a

        t = b_prime
        b_prime = b
        b = t - q * b

    pair = None
    pair = (a, b) if m > n else (b, a)
    return pair