private double find (int a[], int m, int b[], int n, int k)
    {
    	if (m > n)
    		return find(b, n, a, m, k);
    	if (m == 0)
    	{
    		return b[k-1];
    	}
    	if (k == 1)
    	{
    		return Math.min(a[0],  b[0]);
    	}
    	int pa = Math.min(m, k / 2);
    	int pb = k - pa;
    	if (a[pa-1] < b[pb-1])
    	{
    		int[] tmp = Arrays.copyOfRange(a, pa, a.length);
    		return find(tmp, m - pa, b, n, k - pa);
    	}
    	else if (a[pa-1] > b[pb-1])
    	{
    		int[] tmp = Arrays.copyOfRange(b, pb, b.length);
    		return find(a, m, tmp, n - pb, k - pb);
    	}
    	else //equal
    		return a[pa-1];
    }