def symmetric_residue(a, m):
    """Return the residual mod m such that it is within half of the modulus.

    >>> symmetric_residue(1, 6)
    1
    >>> symmetric_residue(4, 6)
    -2

    """
    if a <= m // 2:
        return a
    return a - m
