#include<iostream>
#include<string>
using namespace std;
 bool isLeap(int year){
     if (year %400 == 0) return true;
     if (year %100 == 0) return false;
     if (year %4 == 0) return true;
     return false;
     
 }
 int main (){
     string date;
     cin>>date;
      if (date.length() !=10 || date [4] !=  '_' || date[7] != '_') {
          cout<<"Invalid input";
          return 0;
      }
      for (int i=0;i<10;i++){
          if(i==4||i==7)continue;
          if(!isdigi(date[i])){
              cout<<"Invalid input"
              return 0;
          }
      }
      int year = stoi(date.substr(0,4));
      int month =stoi(date.substr(5,2));
      int day =stoi(date.substr(8,2));
      
      if (year < 1900 || year > 2100 || month < 12 || day < 1){
          cout<<"Invalid input";
          return 0;
      }
      int daysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
      
      if (isLeap(year))
      daysInMonth[1] = 29 ;
      
      if (day > daysInMonth[month - 1]) {
          cout<<"Invalid input";
          return 0;
      }
      int dayNumber=day;
      for(int i=0;i<month-1;i++)
      dayNumber+=daysInMonth[i];
      cout<<daysNumber;
      return 0;
     
 }