#include <cstdio>
#include <string>
#include <algorithm>
int year,month,day,eyear,emonth,eday,ans = 0;
bool runnian(){
if (year % 4 == 0){
if (year % 100 == 0 && !(year % 400 == 0)) return 0;
return 1;
}
return 0;
}
int max(int x){
if (x == 2) return runnian() ? 29 : 28;
if (x < 7) return x % 2 ? 31 : 30;
if (x == 7 || x == 8) return 31;
return x % 2 ? 30 : 31;
}
bool earlier(){
if (year != eyear) return year < eyear;
if (month != emonth) return month < emonth;
return day <= eday;
}
bool huiwen(){
char s[100];
std::string str,str2;
sprintf(s,"%04d%02d%02d",year,month,day);
str2 = str = s;
std::reverse(str.begin(),str.end());
return str2 == str;
}
void update(){
day++;
if (day > max(day)) day %= max(day),month++;
if (month > 12) month %= 12,year++;
}
int main(){
scanf("%4d%2d%2d",&year,&month,&day);
scanf("%4d%2d%2d",&eyear,&emonth,&eday);
while (earlier())
huiwen() && ans++,update();
printf("%d\n",ans);
return 0;
}