package jp.funnything.competition.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.commons.io.IOUtils;

public class QuestionReader {
    private final BufferedReader _reader;

    public QuestionReader( final File input ) {
        try {
            _reader = new BufferedReader( new FileReader( input ) );
        } catch ( final FileNotFoundException e ) {
            throw new RuntimeException( e );
        }
    }

    public void close() {
        IOUtils.closeQuietly( _reader );
    }

    public String read() {
        try {
            return _reader.readLine();
        } catch ( final IOException e ) {
            throw new RuntimeException( e );
        }
    }

    public BigDecimal[] readBigDecimals() {
        return readBigDecimals( " " );
    }

    public BigDecimal[] readBigDecimals( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigDecimal[] values = new BigDecimal[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigDecimal( tokens[ index ] );
        }

        return values;
    }

    public BigInteger[] readBigInts() {
        return readBigInts( " " );
    }

    public BigInteger[] readBigInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigInteger[] values = new BigInteger[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigInteger( tokens[ index ] );
        }

        return values;
    }

    public int readInt() {
        final int[] values = readInts();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public int[] readInts() {
        return readInts( " " );
    }

    public int[] readInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final int[] values = new int[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Integer.parseInt( tokens[ index ] );
        }

        return values;
    }

    public long readLong() {
        final long[] values = readLongs();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public long[] readLongs() {
        return readLongs( " " );
    }

    public long[] readLongs( final String separator ) {
        final String[] tokens = readTokens( separator );

        final long[] values = new long[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Long.parseLong( tokens[ index ] );
        }

        return values;
    }

    public String[] readTokens() {
        return readTokens( " " );
    }

    public String[] readTokens( final String separator ) {
        return read().split( separator );
    }
}

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;


public class Case implements Runnable {

	private int id;
	private String output;

	private int a;
	private int b;
	private String sa;
	private String sb;
	private ArrayList<Couple> hs = new ArrayList<Couple>();

	public Case(int id, int a, int b) {
		super();
		this.id = id;
		this.a = a;
		this.b = b;
	}

	public String solve() {
		int l = (int) (Math.log10(a)) + 1;
		for (int i = a; i <= b; i++) {
			for (int j : shifts(i)) {
				if (i != j && j >= a && j <= b && (((int) (Math.log10(j)) + 1) == l)) {
					Couple c = new Couple(i, j);
					if (!hs.contains(c))
						hs.add(c);
				}
			}
		}
		return String.valueOf(hs.size());
	}

	private int[] shifts(int i) {
		int l = (int) (Math.log10(i)) + 1;
		int[] dgt = new int[l];
		int[] shf = new int[l-1];
		int j = i;
		for (int k = l; k > 0; k--) {
			dgt[l-k] = j / pow(k-1);
			j = j % pow(k-1);
		}
		for (int k = 1; k < l; k++) {
			int x = 0;
			for (int h = 0; h < l; h++) {
				x = 10 * x + dgt[(k+h)%l];
			}
			shf[k-1] = x;
		}
		return shf;
	}

	private int pow(int n) {
		switch(n) {
		case 0:
			return 1;
		case 1:
			return 10;
		case 2:
			return 100;
		case 3:
			return 1000;
		case 4:
			return 10000;
		case 5:
			return 100000;
		case 6:
			return 1000000;
		case 7:
			return 10000000;
		case 8:
			return 100000000;
		case 9:
			return 1000000000;
		}
		return 0;
	}

	private int pow99(int n) {
		int k = 1;
		int pow = 9;
		for (int i = 1; i < n; i++)
			pow = pow * 10 + 9;
		return pow;
	}

	@Override
	public void run() {
		output = solve();
	}

	@Override
	public String toString() {
		return "Case #" + id + ": " + output;
	}

}