Random rand = new Random(System.currentTimeMillis());
    int a = rand.nextInt(100000000);
    int b = rand.nextInt(100000000);

    int min = a;
    int max = b;
    if( b < a ){
        min = b;
        max = a;
    }

    int m = min % 10;
    if(m == 0){
        min = min - 9;
    }else{
        min = min - m;
    }

    int[] plusArray = new int[]{9,1};

    int sum = 0;
    while(min < max){
        for(int plus : plusArray){
            min += plus;
            if(min > max){
                break;
            }

            int tmp = min;
            while(tmp > 0){
                int n = tmp % 10;
                if(n == 0 || n == 9){
                    sum++;
                }
                tmp = tmp / 10;
            }
        }
    }
    System.out.println(sum);