package jp.funnything.competition.util;

import java.math.BigInteger;

/**
 * Utility for BigInteger
 */
public class BI {
    public static BigInteger ZERO = BigInteger.ZERO;
    public static BigInteger ONE = BigInteger.ONE;

    public static BigInteger add( final BigInteger x , final BigInteger y ) {
        return x.add( y );
    }

    public static BigInteger add( final BigInteger x , final long y ) {
        return add( x , v( y ) );
    }

    public static BigInteger add( final long x , final BigInteger y ) {
        return add( v( x ) , y );
    }

    public static int cmp( final BigInteger x , final BigInteger y ) {
        return x.compareTo( y );
    }

    public static int cmp( final BigInteger x , final long y ) {
        return cmp( x , v( y ) );
    }

    public static int cmp( final long x , final BigInteger y ) {
        return cmp( v( x ) , y );
    }

    public static BigInteger div( final BigInteger x , final BigInteger y ) {
        return x.divide( y );
    }

    public static BigInteger div( final BigInteger x , final long y ) {
        return div( x , v( y ) );
    }

    public static BigInteger div( final long x , final BigInteger y ) {
        return div( v( x ) , y );
    }

    public static BigInteger mod( final BigInteger x , final BigInteger y ) {
        return x.mod( y );
    }

    public static BigInteger mod( final BigInteger x , final long y ) {
        return mod( x , v( y ) );
    }

    public static BigInteger mod( final long x , final BigInteger y ) {
        return mod( v( x ) , y );
    }

    public static BigInteger mul( final BigInteger x , final BigInteger y ) {
        return x.multiply( y );
    }

    public static BigInteger mul( final BigInteger x , final long y ) {
        return mul( x , v( y ) );
    }

    public static BigInteger mul( final long x , final BigInteger y ) {
        return mul( v( x ) , y );
    }

    public static BigInteger sub( final BigInteger x , final BigInteger y ) {
        return x.subtract( y );
    }

    public static BigInteger sub( final BigInteger x , final long y ) {
        return sub( x , v( y ) );
    }

    public static BigInteger sub( final long x , final BigInteger y ) {
        return sub( v( x ) , y );
    }

    public static BigInteger v( final long value ) {
        return BigInteger.valueOf( value );
    }
}

import java.io.*;
import java.util.Scanner;
 
public class functions {
	int solve(String A, String B){

		int result = 0;

		int n = A.length();
		int a = Integer.parseInt(A);
		int b = Integer.parseInt(B);
		int i = 0, j = 0, k = 0, index = 0;
		String temp_a = A;
		String temp2 = "";
		int[] array = new int[8];
		for(i = 0; i<8;i++) array[i] = -1;
		
		i = 0;
		int jj = 0,kk = 0;
		while(Integer.parseInt(A) < b-1){
			
			for( index = 0; index <= n-2; index++){
				temp2 = "";
				kk = 0;
				for(j = index; j >= 0; j--){
					temp2 = temp2 + A.charAt(n-1-j);
				}
				for(k = 0; k < n-index-1; k++){
					temp2 = temp2 + A.charAt(k);
				}
				
				int c = Integer.parseInt(temp2);
				if ( c <= b && c > Integer.parseInt(A)) {
					for(jj = 0; jj < 8; jj++){
						if(array[jj] == c){
							break;
						}
					}
					if(jj == 8){
					result = result + 1;
					array[kk++] = c;
					}
					System.out.println("("+A+","+temp2+")");
				}

			}
			A = Integer.toString(Integer.parseInt(A)+1);
			i++;
		}
		
		return result;
	}
}
