import java.io.*;

public class photo_ak_wa {
    static class Date implements Comparable<Date> {
        private static int[] DAYS_IN_MONTH = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        boolean isNowLastDayOfMonth() {
            if (month == 2 && isNowVisokosnyYear()) {
                return day == DAYS_IN_MONTH[2] + 1;
            }
            return day == DAYS_IN_MONTH[month];
        }

        private boolean isNowVisokosnyYear() {
            if (year % 4 == 0)
                return true;
            return false;
        }

        private int day, month, year;

        Date(String s) {
            day = Integer.parseInt(s.substring(0, 2));
            month = Integer.parseInt(s.substring(3, 5));
            year = Integer.parseInt(s.substring(6, 10));
            assert 1 <= month && month <= 12;
            assert 1 <= day && day <= DAYS_IN_MONTH[month] + ((isNowVisokosnyYear() && month == 2) ? 1 : 0);
        }

        @Override
        public int compareTo(Date d) {
            if (d.year != year)
                return year - d.year;
            if (d.month != month)
                return month - d.month;
            return day - d.day;
        }

        void next() {
            if (isNowLastDayOfMonth()) {
                if (month == 12) {
                    year++;
                    month = 1;
                } else {
                    month++;
                }
                day = 1;
            } else {
                day++;
            }
        }

        static private boolean matches(char a, char b) {
            return a == b || a == '?' || b == '?';
        }

        boolean matches2(char[] a, int b) {
            return matches(a[0], (char) ((b / 10) + '0')) && matches(a[1], (char) ((b % 10) + '0'));
        }

        boolean matches4(char[] a, int b) {
            for (int i = 0; i < 4; i++) {
                if (!matches(a[3 - i], (char) ((b % 10) + '0'))) {
                    return false;
                }
                b /= 10;
            }
            return true;
        }

        boolean matches(char[][] pattern) {
            return matches2(pattern[0], day) && matches2(pattern[1], month) && matches4(pattern[2], year);
        }

        public String toString() {
            return String.format("%02d.%02d.%04d", day, month, year);
        }
    }

    void solve() throws IOException {
        char[][] photo = new char[3][];
        {
            String[] photo1 = in.readLine().trim().split("\\.");
            assert photo1.length == 3;
            assert photo1[0].length() == 2;
            assert photo1[1].length() == 2;
            assert photo1[2].length() == 4;
            for (int i = 0; i < 3; i++)
                photo[i] = photo1[i].toCharArray();
        }
        Date start = new Date(in.readLine().trim());
        Date finish = new Date(in.readLine().trim());
        assert start.compareTo(finish) <= 0;
//        assert start.compareTo("01.01.1970")
        int ans = 0;
        while (start.compareTo(finish) <= 0) {
            if (start.matches(photo)) {
                ans++;
            }
            start.next();
        }
        out.println(ans);
    }

    static BufferedReader in;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new FileReader(new File("photo.in")));
        out = new PrintWriter("photo.out");
        new photo_ak_wa().solve();
        out.close();
    }
}
