#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

long long month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

long long checkd(long long y, long long m, long long d){
  if(y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)){
    month[2] = 29;
  }
  else{
    month[2] = 28;
  }
  
  if(m < 1 || m > 12){
    return 0;
  }

  if(d >= 1 && d <= month[m]){
    return 1;
  }

  return 0;
}

long long f(long long y, long long m, long long d){
  long long y1=1;
  long long m1=1;
  long long d1=1;
  long long week=0;
  long long ret = 0;
  long long dd = y/2800;
  y%=2800;
  y+=2800;
  for(;;){
    if(d1==13&&week==4)ret++;
    if(y==y1&&m==m1&&d==d1)break;
    if(checkd(y1,m1,d1)==0){
      if(m1==12){
        y1++;
        m1=1;
        d1=1;
      }
      else{
        m1++;
        d1=1;
      }
      continue;
    }
    else{
      d1++;
      week++;
      week%=7;
    }
  }
  return ret+4816*(dd-1);
}

long long f2(long long y, long long m, long long d){
  long long y1=1;
  long long m1=1;
  long long d1=1;
  long long week=0;
  y%=2800;
  y+=2800;
  for(;;){
    if(y==y1&&m==m1&&d==d1)break;
    if(checkd(y1,m1,d1)==0){
      if(m1==12){
        y1++;
        m1=1;
        d1=1;
      }
      else{
        m1++;
        d1=1;
      }
      continue;
    }
    else{
      d1++;
      week++;
      week%=7;
    }
  }
  return week;
}

int main(){
  long long y1,m1,d1,y2,m2,d2;
  cin>>y1>>m1>>d1>>y2>>m2>>d2;
  long long a = 0;
  if(d1==13&&f2(y1,m1,d1)==4)a=1;
  cout << f(y2,m2,d2)-f(y1,m1,d1)+a << endl;
  return 0;
}
