int binarySearchBound(int[][]mx, int k, boolean lower) {
		for (int m=mx.length,n=mx[0].length,l=0,r=m*n-1;l<=r;) {
			int mid=l+(r-l)/2;
			if (mx[mid/n][mid%n]==k) {
				if (lower)
					if (!equal(mx, mid, mid-1)) return mid;
					else r=mid-1;
				else 
					if (!equal(mx, mid, mid+1)) return mid;
					else l=mid+1;
				
			} else if (mx[mid/n][mid%n]<k) l=mid+1;
			else r=mid-1;
		}
		return -1;
	}