const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
/**
 * 是否正常日期
 */
function validity(date) {
    const year = +date.substring(0, 4);
    const month = +date.substring(4, 6);
    const day = +date.substring(6, 8);
    const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400;
    const months = [
        0,
        31,
        isLeap ? 29 : 28,
        31,
        30,
        31,
        30,
        31,
        31,
        30,
        31,
        30,
        31,
    ];
    return month > 0 && month < 13 && day <= months[month];
}

void (async function () {
    // Write your code here
    let num = 0;
    const start = await readline()
    const end = await readline()
    const syear = start.substring(0, 4);
    const eyear = end.substring(0, 4);
    for (let i = 0; i < eyear - syear + 1; i++) {
        const date = (+syear + i).toString()
        const tyear = date + date[3] + date[2] + date[1] + date[0];
        if (validity(tyear) && +tyear >= +start && +tyear <= +end) {
            num++;
        }
    }
    console.log(num);
})();