public static int Mod(int x, int m) {
        if (m < 0) m = -m;
        int r = x % m;
        return r < 0 ? r + m : r;
    }
public static int Mod ( int x , int m ) { if ( m < 0 ) m = - m ; int r = x % m ; return r < 0 ? r + m : r ; }
Gets the proper modulus operation.

@param x Integer.
@param m Modulo.
@return Modulus.