def gcd(p, q):
    p = abs(int(p))
    q = abs(int(q))
    while q:
        p, q = q, p % q
    return p